How do I create if and else-if statements??

0 favourites
  • 4 posts
From the Asset Store
Fully commented source code/event sheet & sprites to create a space shooter game
  • I have a spaceship that moves left and right, but IF i press left key, it plays left animation ELSE IF i press right key, it plays right animation ELSE play idle animation. Does anyone know how to do this? Even better, is there a way to code using line code, not block code? Thanks :)

  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • All events are 'if' block. There's generally no need to specify else.

    You can add an system condition else, which states that the event will only run if the previous event did not run in and given tick. Also events run top to bottom. The whole sheet is processed every tick, so if your idle animation event is above your other two, it can normally run every tick and will get overwritten by the other animations when those events activate.

    Else is normally used in cases such as toggles, where one event says if x, then change to y, and the following event says if y, then change to x. Since there will both be true, the toggle can never change to y. This can be solved with the else condition.

    You can use JavaScript directly in Construct 3, although in my opinion that kind of defeats the whole point of C3 in the first place. One of the main selling points for me was how logically intuitive the event system was.

  • You can just specify if no key is down play idle and the rest is obvious I guess.

    You can have else if type of thing.

    Do your first action ( If key LEFT is down for example )

    Then add else below that, then add another condition in the same event ( If RIGHT is down )

    then finally add another else below that without any other conditions where you add play idle animation

  • You can use a system like that.

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