Create event event order

0 favourites
  • 6 posts
From the Asset Store
Fully commented source code/event sheet & sprites to create a space shooter game
  • does the create event execute before the variables set after spawning the object?

    or does it work in line order?

    for example witch var would be set first in a code like this?

    on X pressed
    spawn projectile at layer 1 point 0
    projectile set instance var1 to 1
    on projectile created
    projectile set instance var2 to 1
  • Both var1 and var2 will be set to 1 but C2 works in a cascading hierarchy. When a layout is started C2 reads down the list top to bottom going through each event so long as the conditions are meet. The important thing to understand about the coding is what events take priority over others.

    So if you have something like a bomb we are detonating at random

    On Layout Start -> Set var1 == 0

    For EveryTick -> Set var1 == round(random(0,9))

    On Function "Boom" -> Destroy SpriteBomb & Play Boom sound clip

    If var 1 == 5 -> Then do function "Boom"

    In this case c2 looks from top to bottom for conditions it first sees On Layout Start which has a green arrow, meaning it is done first. So var1 is set to 0, this is also a condition that triggers once and is done unless the layout is restarted.

    next going down it sees EveryTIck, Every Tick is a way to say "Always do this till I say stop" so every moment the game is running it is setting var1 to a random number between 0 and 9, it is also being rounded to a whole number. This event will continue to do its own thing without the program really having to do anything

    Next is a Function called "Boom" Since it has not had it triggered it skips it entirely

    Next is a condition seeing if var1 is equal to 5. It will bounce back in forth between the Everytick and this condition till the condition is meet. once var1=5 then the function is called and it skips straight to it. Note "Boom" is specific so you can have as many functions in a event sheet as you want and know that one trigger can do more than one action provided that each on function matches the string that the function is called

    Finally there is a exploding animation then the sprite is destroyed and then a sound fx is played in that order

    Events only matter what order they come in if they have either the same trigger. otherwise most of your event sheet will be inactive but c2 runs that checklist constantly till a condition is meet

    I hope this was helpfull


  • so they would both be set at the same time?

    I don't quite understand

  • You could test it yourself..

    One will be set before the other, so if you put something like

    on X pressed

    spawn projectile at layer 1 point 0

    if var2=0 then projectile set instance var1 to 1

    on projectile created

    if var1=0 then projectile set instance var2 to 1

    So whichever event gets run will show you which is set first. You'd use the debugger to check the values.

  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • From my experiences, var2 would be set first.

    I find the "OnCreated" event is like a parameterless constructor in programming languages.

    I wanted to do something like what you did here and I had to use a seperate instance variable "JustCreated" with default value 1. I set up my object when it is 1 and immediately set it back to 0. It is not event based, but works fine.

  • thankyou I will try this when I get the chance

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