How do I nest events in a logical manner?

Get help using Construct 2

Post » Wed Jul 13, 2016 6:46 am

I know this is a vague question, but let me try and explain with a few examples:

I want a sprite to rotate 180 degrees over 1.5 seconds, and when it's done, double its size over 2 seconds, and when it's done, fade out to 0 opacity, and explode when done.

looks like I need some kind of a timeline, which doesn't exist ni C2, as far a I know...
I know I can use groups to make it LOOK better, but is there any way of creating dependencies of events in C2?

so instead of (very rough pseudo code):

Code: Select all
Sprite - Rotate 180*dt
If Sprite.Angle == 180
    Sprite - Set size * 2 * dt (just some psuedo code)
If Sprite.Size = Sprite.size * 2
    Sprite - Set opacity to 0 * dt
If Sprite.opacity == 0
    Spawn particle


it would be:

Code: Select all
Sprite - Rotate 180*dt
    On Done
         Sprite - Set size * 2 * dt (just some psuedo code)
         On Done
              Sprite - Set opacity to 0 * dt
                  On Done
                       Spawn particle


Thanks!
B
18
S
7
G
1
Posts: 160
Reputation: 1,934

Post » Wed Jul 13, 2016 7:12 am

You need to create a state machine... it's pretty easy and will allow conditional flow for stages of any process.

Give your object an instance variable called "state" or somethung similar... then compare it's value for each stage of your machine.

State =0
--- do something

Something is done
--- set state to 1

State=1
--- do next thing

Next thing is done
--- set state to 2

Etc etc

~Sol
Tired of crappy file hosts that are crappy? Get DROPBOX - https://db.tt/uwjysXJF
Moderator
B
84
S
34
G
40
Posts: 3,032
Reputation: 30,499

Post » Wed Jul 13, 2016 8:01 am

SoldjahBoy wrote:You need to create a state machine... it's pretty easy and will allow conditional flow for stages of any process.

Give your object an instance variable called "state" or somethung similar... then compare it's value for each stage of your machine.

State =0
--- do something

Something is done
--- set state to 1

State=1
--- do next thing

Next thing is done
--- set state to 2

Etc etc

~Sol


Well, it's basically what I wrote in example 1, only using states instead of actual check of the value/condition.
I was hoping for a way of nesting it logically....

Even if there was a way of inserting an "on every tick" event under a condition, that would be great, so I can nest them logically, although their execution order was the same as nesting the checks on the top most hierarchy...
B
18
S
7
G
1
Posts: 160
Reputation: 1,934

Post » Wed Jul 13, 2016 8:44 am

Your expectation is in contradiction with how events work.

Remember they are read top to bottom.
This means that there is no interest for you to "nest" the way you want to do in your second example, since the several conditions/events are at the same level and will be read/checked/executed over many ticks. By having same level sub-events of a parent event, you are already nesting logically the execution.

Due to the fact the action will happen over many ticks (and not in just one or a few) you can't expect a "wait for signal" or "On done" to happen.

All you can do is have the best condition possible that will allow you to define several states.
Expect to have to check for ranges to go from a state to another.
Your code would become something like

Code: Select all
1 Sprite Boolean ToModify is True
2 - Sprite Angle < 180 ... Sprite Rotate angle + 180 * dt
3 - - Sprite Angle >= 180 ... Sprite set Angle = 180
4 - Sprite Angle = 180 & Sprite Size < OriginalSize * 2 ... Sprite - Set size * 2 * dt
5 - - Sprite.Size >= Sprite.OriginalSize *2 ... Sprite.Size = Sprite.OriginalSize * 2
6 - Sprite.Size = Sprite.OriginalSize*2 & Sprite.Opacity > 0 ... Sprite - Set opacity to Opacity - 100 * dt
7 - - Sprite.Opacity <= 0 & TriggerOnce ... Spawn Particle; Set Boolean ToModify to False;  (or) Destroy Sprite


Notice how 3, 5 and 7 are sub-events to a sub-events, checking for the state/range allowing then to ignore the conditions/execution of their to level event yet allowing for the execution of the next.

You could very well "externalise" some execution using the Function object.
But you won't prevent having to use conditions to check the state of your current object, whether you use a state variable, or use some direct property check.
New to Construct ? Where to start

Image Image

Image Image

Please attach a capx to any help request or bug report !
Moderator
B
296
S
119
G
96
Posts: 7,332
Reputation: 71,306

Post » Wed Jul 13, 2016 11:25 am

An example based on states and timers.

https://drive.google.com/open?id=0B1SSu ... Hd2OUlmcEE

This is assuming that there can be many sprites dooing the sequence at the same time. So, every variable and timer is private. Including the 'state', what a 'state' is meant for anywayz. A 'state' is a private thing, any sprite can be in a 'state'.

Mind the scale thing. It is a difficult thing to work with. It has no expressions. And the scale of a sprite = original size * scale. (NOT current size).

Timers are allready dt corrected.

Basecaly this handles 3 things.
1 / do something based on a 'state'. (as you asked)
3 / change variables from a start value to an end value in a given time
4 / change the 'state' based on time
B
33
S
18
G
28
Posts: 2,493
Reputation: 20,950

Post » Thu Jul 14, 2016 7:12 am

Thank you all, I kinda get it now :)
Wish there was some kind of signaling mechanism to C2, but I guess the current model isn't too bad, seeing the explanations :)
B
18
S
7
G
1
Posts: 160
Reputation: 1,934

Post » Thu Jul 14, 2016 7:20 am

System has a 'signal' action & condition.

It is usefull. But not in the way that you expect.

The 'draw system' needs room and time to do its thing. You dont see it in your events, yet it is there in way that you can not overlook it. It usely draws the screen at the end of the event.

So, when you change a sprite, and you expect to see it changing, you can not cage the changes in a loop. You need to pass the end of the event sheet, to let it draw, and start from top again. That = 1 tick.
B
33
S
18
G
28
Posts: 2,493
Reputation: 20,950


Return to How do I....?

Who is online

Users browsing this forum: No registered users and 18 guests