Destroying All Actors Before Advancing to Next Level

jblb2424jblb2424 Member Posts: 65
edited April 2012 in Working with GS (Mac)
Hey All,
Im currently working on a game simply where a ball must reach a finish line on the scene. However, to accomplish this the ball has to destroy all coins in the scene by rolling over them before the finish line appears and allows him to advance to the next level. In some levels, there might be two coins in the scene, and in others there might be ten. Only one problem, i don't know how to create this in my game. Does anyone out there think they can help me out? Thanks! :D

Best Answers

  • tatiangtatiang Posts: 11,949
    edited April 2012 Accepted Answer
    Basically, you need a counter game attribute. So create an integer attribute called game.CoinCounter and start it at 0. In your coin actor, have a rule at the top that says change attribute game.CoinCounter to game.CoinCounter+1. This makes it so that if there are 4 coins on the level, game.CoinCounter becomes 4, and if there are 29 coins then game.CoinCounter becomes 29, etc.

    For any rules that destroy the coin actor, add a change attribute BEFORE the destroy behavior that says change attribute game.CoinCounter to game.CoinCounter-1. So if you have 29 coins and you destroy 1, game.CoinCounter goes down to 28. If you have 1 coin left and you destroy it, game.CoinCounter goes down to 0.

    On your level control actor or main character or wherever you plan to check to see if the coins have been destroyed, have a rule inside of a timer set to after 0.1 seconds* that says When attribute game.CoinCounter=0 [go the next level].

    *The timer is important because without it, when you start a level the game.CoinCounter will be 0 for a brief instant before all of your coins start to increase the value of it.

    I made a video that describes this here:

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

  • MotherHooseMotherHoose Posts: 2,456
    Accepted Answer
    @tatiang … excellent video for Change to Next Level!

    rather than multiple edit/copy actions

    in actorEditor with correct Rules/Behaviors:
    --hold down shiftKey
    --click once to highlight each Rule/Behavior you want to copy
    --click Create Group

    in LibraryPane Behavior:
    --click Custom
    --drag that Group there
    --click scene
    --drag the Group from Custom to each actor you want to have those Rules/Behaviors

    delete the Custom Group … or ignore … as Custom Behaviors are only referenced in development … not in build

    ==
    love your use of notes!

    --MH
Sign In or Register to comment.