Using Tables to Start and Stop Music

VibraKnifeVibraKnife Member Posts: 60
edited August 2012 in Working with GS (Mac)
I have a game I'm working on, and music is playing in the background. I want players to have the option to start and stop it using tables, but I don't know anything about tables! Can someone help?

Best Answer

  • gyroscopegyroscope I am here.Posts: 6,598
    edited August 2012 Accepted Answer

    Rule: When touch is pressed
    Rule (nested with above): When scene.ToggleIcon is false
    Change Image to On icon
    Play Music
    Change Attribute scene.ToggleIcon to true
    Otherwise
    Change Image to Off icon
    Stop Music
    Change Attribute scene.ToggleIcon to false

    There's nothing that can go wrong with that simple set of Rules/behaviours...

    There is one small amendment though; probably best to make the scene attribute ToggleIcon a game attribute.

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

Answers

  • gyroscopegyroscope I am here.Member, Sous Chef, PRO Posts: 6,598
    edited August 2012

    @VibraKnife

    Hallo, tables are very useful in GSC and can help out with the more complex tasks to be made easier. There are quite a few tutorials on tables, one being in the Cookbook that'll teach you about them:

    http://cookbook.gamesalad.com/tutorials/2/parts/25

    And @tshirtbooth has quite a few tutorial videos involving tables at gshelper.com

    So back to your question, you could use tables to solve your problem but it really isn't necessary in this case; it's really straightforward, using a boolean attribute and a few rules/behaviours.

    I've quickly amended a file I did for someone else to include the start and stop music aspect that'll help you:

    https://dl.dropbox.com/u/14060718/MUSIC ON OFF DG.gameproj.zip

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

  • VibraKnifeVibraKnife Member Posts: 60
    @gyroscope That only re-starts the song. Afterwards, It locks up. Then I can't toggle it. Anyone else have any ideas?
  • gyroscopegyroscope I am here.Member, Sous Chef, PRO Posts: 6,598
    edited August 2012
    @gyroscope That only re-starts the song.
    Your question asks for Starting and Stopping music, not playing and pausing music.
    @gyroscope Afterwards, It locks up. Then I can't toggle it.
    You must have copied the rules incorrectly or added something to make that happen. It works fine this end.
    @gyroscope Anyone else have any ideas?
    I could amend the file to make it work with a pause, as you now want, but can't be bothered to help you now or in the future after this brush-off; so yeah, "Anyone else have any ideas?"

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

  • gyroscopegyroscope I am here.Member, Sous Chef, PRO Posts: 6,598
    edited August 2012

    And rejecting my answer doesn't make what I said incorrect either. I guess you'll be rejecting this comment as well.

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

  • VibraKnifeVibraKnife Member Posts: 60
    I am making it a start and stop. It just seems to act weird. I copied the rules exactly, and it still doesn't work. I don't know why.
  • VibraKnifeVibraKnife Member Posts: 60
    I'm not saying its wrong, It just doesn't seem to work on my game
  • gyroscopegyroscope I am here.Member, Sous Chef, PRO Posts: 6,598
    edited August 2012

    OK, @VibraKnife – just to confirm then, do you want your music to start and stop, then start again from the beginning, etc; or start, then pause, then carry on, etc?

    If it's the second one, let me know, and I'll amend the file soon and post it for you.

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

  • VibraKnifeVibraKnife Member Posts: 60
    The first one
  • gyroscopegyroscope I am here.Member, Sous Chef, PRO Posts: 6,598
    edited August 2012

    In that case, the game file I put together works fine here and so should work fine for you as well; I'm not certain why you're finding it wrong.

    Give me a minute and I'll write the Rules here from the game file for you to check against the copied rules in your game.

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

  • gyroscopegyroscope I am here.Member, Sous Chef, PRO Posts: 6,598

    And as the gamefile I amended included changing the button graphic, which you didn't ask for in your question, here it is without that, in case you don't want that:

    Rule: When touch is pressed
    Rule (nested with above): When scene.ToggleIcon is false
    Play Music
    Change Attribute scene.ToggleIcon to true
    Otherwise
    Stop Music
    Change Attribute scene.ToggleIcon to false

    And just change ToggleIcon to ToggleMusic or something.

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

  • VibraKnifeVibraKnife Member Posts: 60
    Thanks! It finally works! I must have missed the otherwise part.
  • gyroscopegyroscope I am here.Member, Sous Chef, PRO Posts: 6,598

    OK, glad it worked out in the end. :-) (Shame you can't "un-reject" my answers...) :P

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

  • VibraKnifeVibraKnife Member Posts: 60
    Yeah \:D/
Sign In or Register to comment.