Button Changing Boolean

dshoedshoe Member Posts: 62
edited November -1 in Working with GS (Mac)
Sup GS, I'm trying to make an actor that when pressed will either turn off or turn on a boolean attribute called EraserIsOn depending on whether it is true or false at the time.

Here is my code

If (touch is pressed)
{
If (EraserIsOn == false)
{
EraserIsOn = true;
}
Else (EraserIsOn == true)
{
EraserIsOn = false;
}
}

The product is the attribute changing once, but the second time you press it, it stays the same (actually I noticed it changes but immediately changes back). So what is a way I can change this attribute back and forth with the same actor?

Comments

  • JohnPapiomitisJohnPapiomitis Member Posts: 6,256
    just use a interger attribute and do this

    when touch is pressed change attibute to (attirubte+1)%2

    that will make it so it starts at 0, you press and it turns to 1, and when its one and you press it turns to 0. And it toggles back and forth like that. You can then use 1 and 0 to instead or true and false
  • dshoedshoe Member Posts: 62
    Hell yea! Thanks this is exactly what I needed.
Sign In or Register to comment.