Making a Boolean Switch

SolarPepperStudiosSolarPepperStudios Member Posts: 754
edited May 2013 in Working with GS (Mac)
Hey everyone! This is the first time in a while I've had to come here for coding help! Anyways, I'm trying to make an iOS styled switch that toggles a boolean. That sounds really simple but for some reason it isn't working for me. :-w Here is a screenshot of my code:
image

Comments

  • jamie_cjamie_c ImagineLabs.rocks Member, PRO Posts: 5,772
    What is it that isn't working as expected?
  • SolarPepperStudiosSolarPepperStudios Member Posts: 754
    It won't change the boolean like it should. It is obviously something in my code but it makes sense to me... Here is what I'm trying to do:
    When the actor is touched and if game.boolean is false -
    change game.boolean to true and change image to switchON
    and the exact same thing only opposite for if it is true.
  • jamie_cjamie_c ImagineLabs.rocks Member, PRO Posts: 5,772
    edited May 2013
    I see, I tried to re-build it and got the same thing. I think I got it working though, check out this screen and look how the rules are nested...

  • SolarPepperStudiosSolarPepperStudios Member Posts: 754
    @jamie_c I'll see if that works! Thanks!
  • jamie_cjamie_c ImagineLabs.rocks Member, PRO Posts: 5,772
    You're welcome, if you need the project file for any reason let me know.
  • SolarPepperStudiosSolarPepperStudios Member Posts: 754
    @jamie_c Nope! I got it! Thanks for your help! :)
  • jamie_cjamie_c ImagineLabs.rocks Member, PRO Posts: 5,772
    Anytime!
  • CodeMonkeyCodeMonkey Head Chef, Member, PRO Posts: 1,803
    You have an endless loop there. I would suggest using an integer or index and toggle between 1 and 0.
    When Touch is Pressed
    --Change Attribute: game.toggle = 1-game.toggle

    If you really must have a boolean, add the rule

    If Attribute game.toggle == 1
    --Change Attribute: game.BoolToggle = true
    --Otherwise: Change Attribute: game.BoolToggle = false
Sign In or Register to comment.