help with on/off button.

johnydeejohnydee Member, PRO Posts: 196
How would i get a on/off button when pressed it changes the image of another actor? So basically when i press the on/off button i want another actor to change its image,than when the on/off is pressed again i want the actor to change back to its first image.

Comments

  • ChakkuChakku Member Posts: 1,513
    edited December 2012
    @johnydee

    create a rule and find the actor (within its layer in the expression editor) you want to change using the expression editor.

    Hope this helps.
  • johnydeejohnydee Member, PRO Posts: 196
    ok thanks..
  • SocksSocks London, UK.Member Posts: 12,822
    edited December 2012
    Two actors - A button and the 'actor'.

    First make a game attribute - call it "button on/off" (or something suitable).


    For the button:
    Rule: touch is pressed:
    Change attribute: game.button on/off to 1-button on/off.


    For the 'actor':
    Rule: when attribute game.button on/off = 1 then change image: Set image to 'A' (your first image)
    Otherwise change image: Set image to 'B' (your second image)
  • ChakkuChakku Member Posts: 1,513
    @johnydee

    Did it work? I can make a quick project demo and share it with you if it did not work.

    Just let me know.
  • johnydeejohnydee Member, PRO Posts: 196
    iam kinda confused on how to do it...i tried but its just not happening
  • ChakkuChakku Member Posts: 1,513
    @johnydee

    Ok, I will make a demo file, and share it with you later today.
  • johnydeejohnydee Member, PRO Posts: 196
    ok thanks alot iam going crazy trying to get it right...gonna take a break now and play MC4 lol..
  • UtopianGamesUtopianGames Member Posts: 5,692
    Make a game integer called Button then in the actor you want to press do if touch is pressed change attribute game.Button to ( game.Button+1)%2 so everytime you press the integer will loop from 0-1-0-1-0 etc etc...you can then do a couple of rules like if game.Button = 0 do XXXX and if game.Button = 1 do XXXX

    Darren.
  • ChakkuChakku Member Posts: 1,513
    edited December 2012
    @johnydee and anyone else who needs it

    Here is the demo I made: https://www.dropbox.com/s/lk5al3f7tevg541/ON:OFF GameSalad Demo.gameproj.zip

    Analyze the code and figure out how I did it (trust me, it's pretty straightforward), then use that in your own game.

    Hope this helps.
  • SocksSocks London, UK.Member Posts: 12,822
    edited December 2012
    Here is the demo I made:

    The method I posted above is far simpler, just one simple rule for the actor and one simple rule for the button.

    http://www.mediafire.com/?y6ph5uu3hqn6ad9
  • ChakkuChakku Member Posts: 1,513
    edited December 2012
    @Socks

    Yes, you are correct; yours is simpler.

    I used expression editor, and self boolean attributes. I told him to analyze it, so he could see what I did.

    I was aware that it could be done simpler, but I thought if I showed it to him this way, then he would learn how to use self attributes, and how to access another actor's attributes through expression editor, and how to use rotation as an attribute that can be used in a rule, which would ultimately help in his use of GameSalad.

    Hope you understand my intentions.

    EDIT: @Socks

    Didn't mean to come out sounding harsh. Just wanted to let you know that.

    :)
  • ChakkuChakku Member Posts: 1,513
    @johnydee

    My demo is the same as Socks' demo (except that my button changes pictures from on to off) If you are just looking for a quick solution, then download Socks' demo, as it is a very simple 1-rule demo.

    But if you want to learn a few tricks that can help you in making your games with GameSalad, then download mine and look at the rules; trust me, it's very easy to understand.

    And DeepBlueApps.com's post is a neat trick to learn, too.

    Also Socks' demo uses an alternative way to do it, so download his too to learn that too.

    Hope this helps, and hope your game goes well.
  • johnydeejohnydee Member, PRO Posts: 196
    thanks guys for the info....
  • johnydeejohnydee Member, PRO Posts: 196
    that was good info from all you guys, now how can i make the second image do an action when pressed? i tried adding the rule in the actor but it dosent apply when the image changes.
  • tatiangtatiang Member, Sous Chef, PRO, Senior Sous-Chef Posts: 11,949
    Unless you are specifically using a condition that says When attribute self.image is [something], images have no effect on actor's rules.

    There must be another condition (rule) you're using that is causing a problem.

    New to GameSalad? (FAQs)   |   Tutorials   |   Templates   |   Greenleaf Games   |   Educator & Certified GameSalad User

  • SocksSocks London, UK.Member Posts: 12,822
    Didn't mean to come out sounding harsh. Just wanted to let you know that.
    No problem, you didn't come across as being harsh at all.
Sign In or Register to comment.