GameSalad

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Changing Boolean with change attribute?

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

Comments

  • Braydon_SFXBraydon_SFX Dallas, TexasPosts: 6,113Member, PRO, Bowlboy Sidekick
    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 Posts: 1,362Member
    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 Posts: 81Member
    That's what i tried but it didn't work... lets try it again...
  • GlomGlom Posts: 59Member
    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 Posts: 81Member
    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 Posts: 81Member
    "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 Posts: 1,362Member
    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 Posts: 81Member
    Didn't change anything, the pic isn't changing...
  • JohnPapiomitisJohnPapiomitis Posts: 6,253PRO
    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 Posts: 81Member
    well ya i know how to use integers, but i was just checking how to change booleans.
  • JohnPapiomitisJohnPapiomitis Posts: 6,253PRO
    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 Posts: 45Member
    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 Posts: 334Member
    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 Posts: 334Member
    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 Posts: 9,843Member, Sous Chef, PRO, Senior Sous-Chef
    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 Posts: 22Member
    edited August 2013
    Use this: (game.attribute)+true
    I get this work. I hope it work too for you
  • The_Gamesalad_GuruThe_Gamesalad_Guru Cape CodPosts: 6,429Member, PRO
    All you have to do is type in true or false. change attribute gameboolean to false
  • gyroscopegyroscope I am here.Posts: 6,118Member, Sous Chef, PRO
    edited August 2013
  • TheMoonwallsTheMoonwalls Posts: 3,066Member, Sous Chef, PRO
    Guys, guys, this thread is one year old :P Closing this.
  • gyroscopegyroscope I am here.Posts: 6,118Member, Sous Chef, PRO
    edited August 2013

    @TheMoonwalls

    Whoops! Thanks, Marcin. :-)
This discussion has been closed.