Creating a Pause button, working but not exactly

This forum is currently in read-only mode.
From the Asset Store
_______ Huge collection of metal fixtures ________
  • 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.

  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • 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
  • 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

    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.

  • I just did the following with the 360 controller:

    <img src="http://farm6.static.flickr.com/5109/5674536376_5163bf7cf2.jpg">

    ... 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.

  • 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.

  • 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.

    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

    <img src="http://farm6.static.flickr.com/5265/5675359651_25d7c6ce10_z.jpg">

  • 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.

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