Changing Boolean with change attribute?

igpxnaruto4igpxnaruto4 Member Posts: 81
edited July 2012 in Working with GS (Mac)
How do i change a Boolean with change attribute?

Comments

  • Braydon_SFXBraydon_SFX Member, Sous Chef, PRO, Bowlboy Sidekick Posts: 9,271
    Just do this:

    Change attribute:
    game.yourattriubute to true.
    Or, if you wanted to change it to false do this:
    game.yourattriubute to false.

    Hope this helps
  • AsymptoteellAsymptoteell Member Posts: 1,362
    You can't change an actor's "visible" attribute, though, so if you're running into trouble trying to do that, instead change attribute self.color.alpha to zero or one.

    Asymptoteell
  • igpxnaruto4igpxnaruto4 Member Posts: 81
    That's what i tried but it didn't work... lets try it again...
  • GlomGlom Member Posts: 59
    Make sure you click the 'e' before you input the true or false or other value. I've had trouble with attributes not changing when I just click the textbox and enter the value without clicking the 'e' first.
  • igpxnaruto4igpxnaruto4 Member Posts: 81
    what im trying to do is a make a sound on and off button, what happens is when touch is pressed and sound is true it changes the image, pauses the sound and changes the Boolean to false(Boolean is set to true in the beginning) then i have another rule with the exact opposite. y isn't it working?
  • igpxnaruto4igpxnaruto4 Member Posts: 81
    "Make sure you click the 'e' before you input the true or false or other value. I've had trouble with attributes not changing when I just click the textbox and enter the value without clicking the 'e' first."
    What E?
  • AsymptoteellAsymptoteell Member Posts: 1,362
    Next to the box where you can type, there's a lowercase e that brings up a window (the expression editor where you pick attributes.
  • igpxnaruto4igpxnaruto4 Member Posts: 81
    Didn't change anything, the pic isn't changing...
  • JohnPapiomitisJohnPapiomitis Member Posts: 6,256
    If you want to make a toggle state button like a sound on off button do this.

    Make a interger attribute and call is soundOff have it set to 0

    Have a rule when touch is pressed:
    change attribute to (soundOff+1)%2

    then have a rule when attribute soundOff =1
    change attribute device sound volume to 0
    and change image to sound off button image
    then open up the otherwise section of that rule and inside there have this:
    change attribute device sound volume to 1
    change image to sound on button image

    cheers
  • igpxnaruto4igpxnaruto4 Member Posts: 81
    well ya i know how to use integers, but i was just checking how to change booleans.
  • JohnPapiomitisJohnPapiomitis Member Posts: 6,256
    Yes but your saying you want to make a toggle sound button. You would want to use a interger for that so u can use the modulo function i put above so you dont have to have seperate rules and what not checking the conditions each time and all that. The expression i put above will toggle it back and forth for you

    cheers
  • EricTippettEricTippett Member Posts: 45
    Yeah I am having the same problem with booleans.
    I dont know how I would change this to true or false, I tried 1 for true and 0 for false. There is no true or false that I found in the "e".
    I thought these are the best attributes for on/off buttons.
  • ericzingelerericzingeler Member Posts: 334
    If you want to make a toggle state button like a sound on off button do this.

    Make a interger attribute and call is soundOff have it set to 0

    Have a rule when touch is pressed:
    change attribute to (soundOff+1)%2

    then have a rule when attribute soundOff =1
    change attribute device sound volume to 0
    and change image to sound off button image
    then open up the otherwise section of that rule and inside there have this:
    change attribute device sound volume to 1
    change image to sound on button image

    cheers
    boom! done! Booleans are sucky, integers do the same but with the added benefits of using math if you need to.
  • ericzingelerericzingeler Member Posts: 334
    Also, you can get creative with integer switches by using more than 2 states. In many cases, using more than 2 states on a switch can reduce the amount of attributes in your project.
  • tenrdrmertenrdrmer Member, Sous Chef, Senior Sous-Chef Posts: 9,934
    You just type in true or false for booleans no expression editor or anything

    Lowercase true or false is all you need for a Boolean.

    And yes integers are another good option but keep in mind they use a minuscule amount more ram from what I'm told so loads and loads of them could actually make a difference. But either way is really pretty good.
  • GamesITGamesIT Member Posts: 22
    edited August 2013
    Use this: (game.attribute)+true
    I get this work. I hope it work too for you
  • The_Gamesalad_GuruThe_Gamesalad_Guru Member Posts: 9,922
    All you have to do is type in true or false. change attribute gameboolean to false
  • gyroscopegyroscope I am here.Member, Sous Chef, PRO Posts: 6,598
    edited August 2013

    @igpxnaruto4

    ... or: 0 or 1.

    ""You are in a maze of twisty passages, all alike." - Zork        temp domain http://spidergriffin.wix.com/alphaghostapps

  • IsabelleKIsabelleK Member, Sous Chef Posts: 2,807
    Guys, guys, this thread is one year old :P Closing this.
This discussion has been closed.