Else condition

0 favourites
  • 5 posts
  • Hello

    I've been trying to read guides about it but I didnt understand how it works!

    I want to do this thing:

    The goal of my game is that the user need to click as many times as he can on the "space" key, before running out of time.

    When the user clicks starts, the countdown starts from 5 seconds.

    Each space click, the variable "score" increases by 1.

    I have a variable name : "countdown" that decreases by 1 each second.

    After it reached 0, I want to make that it will no more increase the score.

    In other "words:"

    if ($countdown > 0) { Spacebar increases the score! }

    else { Spacebar doesnt! }

  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • Add a condition 'Countdown > 0' in the event for Click Space > Increase by 1

  • Add a condition 'Countdown > 0' in the event for Click Space > Increase by 1

    Thanks works!

    But how do I add an "else"?

  • You don't need an else here, else is if you want something else to happen usually. In this case you just want your action not to happen if the condition is not met.

    Saying "If this is blue then do X" means that if it is not blue, X won't happen so there is no need for an else. Usually you use else if you have multiple options such as:

    If this has color (condition)

    (sub-condition)If this is Blue then do X

    (Sub-condition)If this is Green then do Y

    (sub-condition)If this is red then do z

    Else Assign Random Color to this

    Does that make sense? Else is usually if you want something to happen if none of the other conditions are met, otherwise meeting no conditions means that none of the conditions related actions would fire off.

    You don't have to Say Do this else don't do this. If your condition isn't met it won't do it to begin with so you don't need an else in that case.

  • You could do it like this:

    condition: space bar pressed action: (no action)

    sub-condition: countdown>0 action : somethingsomething



    you can create sub-events by selecting the main event and pressing b

    the reason you chech for space being pressed is because you can't put else to a triggered event.

    I hope I could explain it?

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