More concise way to code this?

Discussion and feedback on Construct 2

Post » Mon Apr 18, 2016 10:59 am

Hi guys

Just wondering whether anyone could give me any tips on a more concise way to code the snippet in the screen grab attached.

Thank you very much in advance for any help :)

https://www.dropbox.com/s/bjwcd3ezl3lkx ... n.jpg?dl=0
B
44
S
22
G
9
Posts: 142
Reputation: 9,053

Post » Mon Apr 18, 2016 11:44 am

I'm confused, why is the Name condition even there if the action is exactly the same every time? Just take it out and have one event?
Image



Coming soon on Steam!
B
16
S
9
G
3
Posts: 204
Reputation: 3,466

Post » Mon Apr 18, 2016 11:53 am

Ohhh are you trying to pick each individual monster eye by name? So that each eye blinks on its own random timer?

OK try this.

Give the MonsterEye an instance variable, we'll call it randomBlink.

Then in events:
Every 1 seconds: MonsterEye add random(1,5) to variable randomBlink
MonsterEye randomBlink>=10: set animation to Animation2, set randomBlink = 0

Just change the second line to whatever number to control the frequency of the blinks :)
Image



Coming soon on Steam!
B
16
S
9
G
3
Posts: 204
Reputation: 3,466

Post » Mon Apr 18, 2016 11:56 am

You could give MonsterEye the Timer behaviour and each could restart with a new random timeout.
ImageImageImage
B
71
S
21
G
229
Posts: 3,686
Reputation: 128,336

Post » Mon Apr 18, 2016 6:16 pm

i agree with blackhornet. seems like the easiest way to control what each instance does.
Sea Monsters template - Isometric
Also includes 40 pages PDF of optimizations and "how-to" for your games, and how the "sea monsters" template was built. Follow link for details :)

sea-monsters-templates-and-assets_t162705
B
42
S
14
G
12
Posts: 624
Reputation: 9,421

Post » Tue Apr 19, 2016 1:10 am

Hi Guys

Thank you very much for all your help! You guys are awesome :)

I've ended up using @blackhornet 's suggestion. It works exactly as I need, and with only 2 lines of code.

1. I give the monster eye a timer behaviour,
2. On Start of Layout, I start the timer with a random timeout.
3. On timeout I switch to the blink animation.

The timer sets up different random number for each instance, which is exactly what I need :)

Thank you again!
B
44
S
22
G
9
Posts: 142
Reputation: 9,053


Return to Construct 2 General

Who is online

Users browsing this forum: Unconnected and 15 guests