Else condition

Get help using Construct 2

Post » Fri Oct 04, 2013 1:07 pm

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! }
Owner of Movies!
B
9
S
2
G
1
Posts: 38
Reputation: 1,168

Post » Fri Oct 04, 2013 1:58 pm

Add a condition 'Countdown > 0' in the event for Click Space > Increase by 1
B
45
S
15
G
73
Posts: 2,007
Reputation: 43,396

Post » Fri Oct 04, 2013 2:22 pm

[QUOTE=plinkie] Add a condition 'Countdown > 0' in the event for Click Space > Increase by 1[/QUOTE]
Thanks works!
But how do I add an "else"?
Owner of Movies!
B
9
S
2
G
1
Posts: 38
Reputation: 1,168

Post » Sat Oct 05, 2013 5:07 am

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.
B
49
S
12
G
10
Posts: 1,833
Reputation: 14,573

Post » Sat Oct 05, 2013 3:51 pm

You could do it like this:
condition: space bar pressed action: (no action)
sub-condition: countdown>0 action : somethingsomething
else
action:somethingelse

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?
B
17
S
4
G
1
Posts: 332
Reputation: 3,099


Return to How do I....?

Who is online

Users browsing this forum: stevenode and 11 guests