How do I nest events in a logical manner?

0 favourites
  • 7 posts
From the Asset Store
14 amazing sound files of game events like Level Ups, Level Completes, object spawn, object taking etc.
  • 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):

    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
    [/code:28apaqo7]
    
    it would be:
    
    [code:28apaqo7]
    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
    [/code:28apaqo7]
    
    Thanks!
  • 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

  • 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...

  • Try Construct 3

    Develop games in your browser. Powerful, performant & highly capable.

    Try Now Construct 3 users don't see these ads
  • 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

    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 
    [/code:tk2og5yt]
    
    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.
  • 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

  • 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

  • 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.

Jump to:
Active Users
There are 1 visitors browsing this topic (0 users and 1 guests)