How to create a on or off button

I'm trying to make a button that turns the music on and off and when its on turns into a different image than when its off. So I tried use change attribute to change the Boolean (Button) to true, and that works fine, but I try to do the same to make it change back it changes for a second and then it quickly changes back. So does anyone know what I should do?

«1

Comments

  • RThurmanRThurman Member, Sous Chef, PRO Posts: 2,880

    Try something like this.

  • Phoenix256Phoenix256 Member Posts: 42

    Sorry that might have helped but I can't download that due to bad internet, any other ideas

  • RThurmanRThurman Member, Sous Chef, PRO Posts: 2,880

    Try this rule for boolean attributes:

    When button is touched
    Change Attribute:[ button  ] To:[ not(button)  ]
    
  • Phoenix256Phoenix256 Member Posts: 42

    Ok that seems like a good idea I will try that, thanks

  • Phoenix256Phoenix256 Member Posts: 42

    Ok, I have tried a lot of different ways to do it, and every time I can make it change the image, but I can't figure out how to change it back, how do I change it back.

  • LovejoyLovejoy Member Posts: 2,078

    @Phoenix256 said:
    Ok, I have tried a lot of different ways to do it, and every time I can make it change the image, but I can't figure out how to change it back, how do I change it back.

    @RThurman just showed you how. If touched if changes a boolean to true, if touched again it changes it to false etc.

    Fortuna Infortuna Forti Una

  • Phoenix256Phoenix256 Member Posts: 42

    ugh

  • RThurmanRThurman Member, Sous Chef, PRO Posts: 2,880

    Maybe its the other part you are having an issue with? That is, how to do one thing when the boolean attribute is true, and do another when it is false? That goes something like this:

    When button is true
        Change color
        Play music
    otherwise
        Change color back
        Stop Music
    
  • Phoenix256Phoenix256 Member Posts: 42

    how do I do that otherwise, because it will change the picture but it wont change back when I press it again

  • RThurmanRThurman Member, Sous Chef, PRO Posts: 2,880

    See that little "otherwise" button in @LoveJoy's picture?

  • Phoenix256Phoenix256 Member Posts: 42

    well mine looks different, in the rule it says "do" and below that it says "other" and I don't even know what that's for.

  • Phoenix256Phoenix256 Member Posts: 42

    my bad it says else below do not other

  • RabidParrotRabidParrot Formally RabidParrot. Member Posts: 956

    @Phoenix256

    Create button

    Make an integer attribute called "game.onoff"

    Rule:

    When touch is pressed change game.onoff to (game.onoff +1)%2

    The game.onoff will switch between 0 and 1.

    So when game.onoff is 0 it will be off

    When game.onoff is 1 it will be on.

  • Phoenix256Phoenix256 Member Posts: 42

    ok I will try that

  • Phoenix256Phoenix256 Member Posts: 42

    it didn't work any thing I try I can get it to change but I press it again it does nothing

  • ArmellineArmelline Member, PRO Posts: 5,354

    This will produce the effect you're looking for, with optional intelligent starting/resuming:


    Project also attached for anyone who wants it. The music in it freaked my cat out majorly, so be warned!

  • LovejoyLovejoy Member Posts: 2,078

    When we say "otherwise" it means the "else" section in windows creator.

    Fortuna Infortuna Forti Una

  • Phoenix256Phoenix256 Member Posts: 42

    good that's clearified

  • Phoenix256Phoenix256 Member Posts: 42

    There is either something I'm doing wrong or my gamesalad program doesn't work wright, because no matter what I do I can change the image but I cant make it change back

  • RThurmanRThurman Member, Sous Chef, PRO Posts: 2,880
    edited April 2015

    Lets try it with 3 separate rules:

    Rule: When touch
         Change Attribute: button To: not(button)
    
    Rule: When button is true
         Change Image
         Play Music
    
    Rule: When button is false
         Change Image
         Stop Music
    
  • Phoenix256Phoenix256 Member Posts: 42

    I already tried that and when I press it changes the image but when I press it again it quickly switches to the first image then right back to the other

  • Phoenix256Phoenix256 Member Posts: 42

    i think my problem is the button is not changing from true to false back to true.

  • Phoenix256Phoenix256 Member Posts: 42

    because when i press it it changes to true, but when i press it again i don't think its changing back to false

  • ArmellineArmelline Member, PRO Posts: 5,354
    edited April 2015

    I showed you the exact logic needed in pictures. Can you show us the logic you are using?

  • Phoenix256Phoenix256 Member Posts: 42

    i cant upload the image i don't know if im doing it right, but i past the url to the embed thing but it doesn't bring up the picture

  • ArmellineArmelline Member, PRO Posts: 5,354

    Just paste the URL of the picture into a post then and we'll click through to look it.

  • Phoenix256Phoenix256 Member Posts: 42
    edited April 2015

    C:\Users\Lester\Pictures\Screenshots\Screenshot (5).png
    C:\Users\Lester\Pictures\Screenshots\Screenshot (6).png
    there are two parts of the picture

  • ArmellineArmelline Member, PRO Posts: 5,354

    @Phoenix256 said:
    C:\Users\Lester\Pictures\Screenshots\Screenshot (5).png
    C:\Users\Lester\Pictures\Screenshots\Screenshot (6).png
    there are two parts of the picture

    Ah, you will need to upload them to an image host, such as http://www.imgur.com before we can see them.

  • Phoenix256Phoenix256 Member Posts: 42

    im using school internet and the site is blocked

  • Phoenix256Phoenix256 Member Posts: 42


    here is the way i have it set up

Sign In or Register to comment.