2 commands with same key

Get help using Construct 2

Post » Wed Mar 07, 2012 2:14 pm

Hey guys, is there anyone who knows how to pause the game with the key
P and then unpause with the same button like on many online games, also i want to do that with sound for Mute on M key. So if any ideas please write.
B
10
S
3
G
3
Posts: 54
Reputation: 3,317

Post » Wed Mar 07, 2012 2:17 pm

I usually have one global object "GameBrain" that holds boolean values that I can toggle on and off.
B
40
S
5
G
5
Posts: 405
Reputation: 5,657

Post » Wed Mar 07, 2012 10:28 pm

Use nemo's suggestion or store them at a global variable.

If you use a global variable, instead of setting boolean (as a global can only be number or text), you'll use a ternary operator to toggle the variable.

For instance:

global variable pause = 0;    //0 = false, so game starts NOT paused

On P pressed: Set pause to (pause = 0 ? 1 : 0)
English is not my native language. Sorry for any mistakes and feel free to correct me if needed.
B
14
S
5
G
3
Posts: 110
Reputation: 3,225

Post » Wed Mar 07, 2012 11:02 pm

On P pressed: Set time scale to timescale = 1? 0:1

No need to use variables. :)
ImageImageImageImage
B
140
S
58
G
36
Posts: 2,547
Reputation: 31,170

Post » Wed Mar 07, 2012 11:05 pm

yup, but i was just showing an example on how to toggle a global :P
English is not my native language. Sorry for any mistakes and feel free to correct me if needed.
B
14
S
5
G
3
Posts: 110
Reputation: 3,225

Post » Wed Mar 07, 2012 11:19 pm

My point was not how to pause the game, but how to pause and unpause with one key, for example P, you know, press P - game is paused, press P again game is unpaused, cant do that for some reason, maybe i am missing something. Thanks for your opinions.
B
10
S
3
G
3
Posts: 54
Reputation: 3,317

Post » Wed Mar 07, 2012 11:25 pm

On P pressed: Set time scale to timescale = 1? 0:1

This is doing what you want. It will pause and unpause the game with one key.


From manual
[quote]?: is a conditional operator, which allows you to test conditions in expressions. This is especially useful when used with the comparison operators and logical operators. It takes the form condition ? result_if_true : result_if_false
e.g. health < 0 | score < 0 ? "Game over!" : "Keep going!".
The condition counts as true if it is non-zero, and false if it is zero.[/quote]shinkan2012-03-07 23:28:51
ImageImageImageImage
B
140
S
58
G
36
Posts: 2,547
Reputation: 31,170

Post » Thu Mar 08, 2012 12:03 am

Ok, thanks...my bad i was writing only 1? 0:1 without timescale =
B
10
S
3
G
3
Posts: 54
Reputation: 3,317

Post » Thu Mar 08, 2012 1:20 am

no need for trinary operator you can just to
On P Pressed -> set timescale to 1-timescale

'cause
1- 1 = 0
1- 0 = 1
B
60
S
22
G
14
Posts: 1,479
Reputation: 16,346

Post » Thu Mar 08, 2012 1:58 am

[QUOTE=Yann] set timescale to 1-timescale[/QUOTE]


B
28
S
8
G
1
Posts: 469
Reputation: 4,683

Next

Return to How do I....?

Who is online

Users browsing this forum: Aserak2012, Colorfish, Waltuo, Yahoo [Bot] and 4 guests