0 Favourites

Toggle state-based button

  • Hi,

    I want to have a button that changes a text variable based on its own state. Per default the variable is 0, button 1 sets the it to 1, button 2 sets value 2. Pressing a button the second time should reset the variable back to zero.

    So I have two' System'>'Compare value' events to toggle the state, but they seem to overwrite one another in the same cylce, effectively setting and resetting the value in a single cycle.

    Can someone point me to a working example of a two button setup that toggle a single variable?

    Here's what mine looks like:

  • looks like a big part of the problem is that I'm simultaneously providing touch and mouse controls, and while mouse alone can be set to work fine, my touch input seems to constantly trigger as well, despite not being on a touch device ...

  • Construct 3

    Buy Construct 3

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

    Buy Now Construct 3 users don't see these ads
  • Set the second condition in each sub event to an else condition. The way you have it set right now, the sub events trigger consecutively meaning, as soon as you set the value"nuke" and "spawn", the second condition is always true.

    Just to be clear, the 2 conditions "Commander.controlmode = 'nuke'" and "Commander.controlmode = 'spawn'" should be changed so it is just an Else event. This means when the condition before it is not true this condition is true.

  • Also, you can combine your click and touch events by placing them in an or block. This will cut down the total number of events you will use by half.

  • I've been trying these things, among others, but the results are variations of what I described:

    when holding the 'spawn' button it flickers, being set on and off

    [attachment=0:ausynbv6][/attachment:ausynbv6]

    when releasing the 'nuke' it immediately resets

    [attachment=1:ausynbv6][/attachment:ausynbv6]

    my real problem i believe is that all the 'On Touch ...' events trigger every cycle during mouse-clicking. which i find mildly disturbing.

    Can I disable touch input when not on a touch device?

    Is there a way to not register onTouch multiple times?

  • Set the touch object to count mouse clicks and remove the mouse click condition unless you need to test for right click.

  • good call, thanks

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