2 commands with same key

0 favourites
  • 13 posts
From the Asset Store
In this game you will command the character by voice command.
  • 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.

  • I usually have one global object "GameBrain" that holds boolean values that I can toggle on and off.

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

  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • On P pressed: Set time scale to timescale = 1? 0:1

    No need to use variables. :)

  • yup, but i was just showing an example on how to toggle a global :P

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

  • 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

    : 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.edited><editID>shinkan</editID><editDate>2012-03-07 23:28:51</editDate></edited>

  • Ok, thanks...my bad i was writing only 1? 0:1 without timescale =

  • no need for trinary operator you can just to

    On P Pressed -> set timescale to 1-timescale

    'cause

    1- 1 = 0

    1- 0 = 1

  • set timescale to 1-timescale

    <img src="http://3.bp.blogspot.com/-nT_sUW45J-g/Tq7niAUStwI/AAAAAAAAAfk/k0Gks20Mdn0/s400/blown%2Bmind.jpg" border="0" />

  • no need for trinary operator you can just to

    On P Pressed -> set timescale to 1-timescale

    'cause

    1- 1 = 0

    1- 0 = 1

    -This is madness!

    -Madness?

    -THIS IS... CLEVER!!! <img src="smileys/smiley7.gif" border="0" align="middle" />

  • Thanks everybody i feel better now :)

  • Hi,

    I've come up with a simple solution that should apply for all instances of using the same key to pause and unpause. It should also work for any other toggle or toggleable events that you might need.

    I've included an image here to show you what it's like: i.imgur.com/NI1oOAJ.jpg

    If that image doesn't come through then here's the basics:

    1) Create a Global Variable and set it to 0

    2) here's the way I input the actions

    | System Every Tick

         | Keyboard on [Key] pressed

            | System [Global Variable] = 0 : Toggles an action, like pause or creating an object etc.

            |                             : Set [Global Variable] to 1

            | System Else                  : un-toggles any previous action, or does a new set of actions.

            |                             : Set [Global Variable] to 0

    That's the basic skeleton. The program will check to see if the variable is 0 or not 0 and will take action based on that. It will be a toggle-able event as long as you remember to reset the Global Variable each time.

    I hope that's clear enough.

    <img src="http://i.imgur.com/NI1oOAJ.jpg" border="0" />

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