Creating a Pause button, working but not exactly

For questions about using Classic.

Post » Sun May 01, 2011 1:35 am

Setting Timescale to zero pauses things, but I couldn't unpause and the characters just stood frozen, so I tried to do something more with events in the following manner:

Event: Start Button is down ---> Action: System - Set time scale to 0

I then used a Global variable with the "add to value" action where on the first press it would add 1 to the value and on the second press it would add 1 again to become '2'. I then put in:

Event:"Is Global variable "Pause" equal to 2? ----> Action: System - Set time scale to 1.0.

... But I can't get it to work because it appears that Construct is adding to the value every milisecond, instead of only increasing the value by 1 each time I press the pause button. It's not even responding at all now, meaning that the characters just keep moving around as normal.

Back in the summer, I had a similar problem with the "add to value" action in regards to Global variables with a different type of thing, but I was able to use "set value" and base the calculation of the value on a collision, and even though it was still buggy it worked to a degree.

I'm stumped.
B
12
S
4
G
3
Posts: 426
Reputation: 2,458

Post » Sun May 01, 2011 1:45 am

By using start button is down, it will add one to the variable each tick as long as the button is down instead of once for the press. Try using:

On start pressed
(subevents)
- if timescale is equal to 1, set timescale to zero
- else, set timescale to 1
Moderator
B
88
S
32
G
33
Posts: 3,005
Reputation: 27,432

Post » Sun May 01, 2011 2:14 am

[quote="Arima":r35dlmru]By using start button is down, it will add one to the variable each tick as long as the button is down instead of once for the press. Try using:

On start pressed
(subevents)
- if timescale is equal to 1, set timescale to zero
- else, set timescale to 1[/quote:r35dlmru]

I should've mentioned that I'm using the 360 controller object. As far as I know, there are no "on pressed" commands for the 360 controller object, only "Control is down", or at least that's all I have in my version.
B
12
S
4
G
3
Posts: 426
Reputation: 2,458

Post » Sun May 01, 2011 2:57 am

I just did the following with the 360 controller:



... and it pauses, except when I release the start button it unpauses. I tried using the keyboard object in its place with the same commands, but it didn't even respond.
B
12
S
4
G
3
Posts: 426
Reputation: 2,458

Post » Sun May 01, 2011 3:39 am

If there is only an "is down" condition for the controller, then refine your first appoach. Add a global "isPaused" and combine the "Start is down" condition with "Trigger once"

+ Start is down
+ Trigger once
-> Set isPaused to 1 - global('isPaused')

This will set isPaused to 1 on every first press of Start, and to 0 on every second. Then add

+ isPaused equal to 1
-> Set time scale to 0
+ else
-> Set time scale to 1

I don't know, if controller buttons are still detected if time scale = 0 (I don't have a controller), but apart from that the events above [s:mjylicny]will[/s:mjylicny] should work.
Image
B
23
S
8
G
10
Posts: 1,820
Reputation: 8,242

Post » Sun May 01, 2011 1:49 pm

[quote="tulamide":2hjfl42f]If there is only an "is down" condition for the controller, then refine your first appoach. Add a global "isPaused" and combine the "Start is down" condition with "Trigger once"

+ Start is down
+ Trigger once
-> Set isPaused to 1 - global('isPaused')

This will set isPaused to 1 on every first press of Start, and to 0 on every second. Then add

+ isPaused equal to 1
-> Set time scale to 0
+ else
-> Set time scale to 1

I don't know, if controller buttons are still detected if time scale = 0 (I don't have a controller), but apart from that the events above [s:2hjfl42f]will[/s:2hjfl42f] should work.[/quote:2hjfl42f]

Works! I wasn't sure if the trigger once command you posted was supposed to be input as an event or a condition, but I tried both and got it to work as a condition.

And with that I'd like to start a new trend of showing a picture of the working events when a help question is solved (hopefully this will catch on):

How to Pause the game

B
12
S
4
G
3
Posts: 426
Reputation: 2,458

Post » Sun May 01, 2011 3:46 pm

Just to clarify, the Trigger Once condition works in conjunction with other conditions in the event. If they are all true, then Trigger Once will allow the actions to take place during that tick. After that tick, if the other conditions remain true, Trigger Once will not allow the actions to take place.

Trigger Once resets when one or more of the other conditions in your event becomes false, so next time they are all true it will trigger again.

Using a Trigger Once all on it's own as a condition is basically the same as using a Start Of Layout condition... it will trigger on the first tick, and then never again after that.
Moderator
B
5
S
2
G
6
Posts: 4,348
Reputation: 10,971


Return to Help & Support using Construct Classic

Who is online

Users browsing this forum: No registered users and 2 guests