Using one button and variable to switch states

0 favourites
  • 7 posts
From the Asset Store
Easily store, modify, read and manipulate colors with Color Variables!
  • Hi everyone,

    I have a newbie issue that I hope someone can help me with.

    In my game, I have two characters that the player swaps between (they're basically invisible and inactive when not in use). I want to have a single button that the player presses to change between them which checks which character is currently in use (either 1 or 0, stored in a global variable).

    My game is currently in a bit of a mess but I've recreated the situation in a new file. I'm not yet permitted to post links but I hope that this will work:

    Or this screenshot will hopefully make sense:

    <img src="" border="0" />

    Thanks in advance :)

  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • Here you go: BlueTester2.capx (r106)

  • Ah, brilliant. Thanks ramones, that makes perfect sense.

  • I'd suggest posting this to the bugs section, this looks like it could be an actual bug. I see no reason why the way you wanted to do it wouldn't work.

    I messed around with it. Seems I can get it to respond to the click when the variable is equal to 0, but not otherwise.

    Edit: I tried it with a boolean, and while it works with toggling the boolean, the problem seems to be precent when setting the boolean manually (makes sense since all the boolean is is a variable with only 0 and 1).

    I would want to check ramones capx to see what he did, but it's not available it seems.

  • Event 2 basically cancels out event 1. If 'isBlue = 1' when you click on the button, you'd think only event 1 would run. But the way I think it works is, when you click, it checks and runs each mouse click event one at a time. So event 1 runs and sets isBlue to 0. And then event 2 is true so it runs and sets isBlue back to 1.

  • I exchanged the mouse clicks with simply pressing space, the problem persists.

    Edit: Also tried with an actual button. Same thing.

    Not sure what the issue is, but there is an issue. That much is clear.

  • I don't think I explained it well. It doesn't matter if it's mouse/keyboard/button.

    In this example you'll agree that var will be 0 every tick regardless of whether it starts as 1 or 0:

    <img src="" border="0" />

    This is the same thing only when space is pressed:

    <img src="" border="0" />

    var will always be 0 because if the first event makes it 1 then the second event will set it back to 0.

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