Next level and timer?

triton13triton13 Member Posts: 161
edited February 2012 in Working with GS (Mac)
Hey guys, I have two questions. The first is, if I have some characters and they are supposed to be destroyed then it goes to the next level, how can I do that? There are still items in the scene but when certain items are destroyed, I want it to move to the next level. Second, how can I add a simple countdown timer to my scene? I don't want the hundredths and thousandths and all that, just a simple 5 4 3 2 1 timer. Thank you

Comments

  • HoneyTribeStudiosHoneyTribeStudios Member Posts: 1,792
    I find taking snap shots of the game timer to be useful when specifying actions that are dependant on specific timings.

    So first you could have an index attribute for your destroyed actors. And have it increment by 1 each time an actor is destroyed. (Obviously that rule goes just before the command to destroy it). Let's call it game.deadStuff
    Then make a real attribute. It could be a scene, game or actor attribute. For now let's say a game attribute: game.timeSnap

    So the rule would be:
    when game.DeadStuff = 3 (or whatever your number is)

    change game.timeSnap to game.time.

    And then another rule:
    When game.time is equal to or more than game.timeSnap+0.5 (or how ever many seconds you want)

    Change scene

    P.S it's good practice to make an attribute for the number of seconds, which is 0.5 in the example above. Then it will be easy to modify your game as you go along without having to click around inside every actor typing things in.
  • tatiangtatiang Member, Sous Chef, PRO, Senior Sous-Chef Posts: 11,949
    Give each "enemy" actor the behavior Change Attribute game.EnemyCount = game.EnemyCount+1. This behavior will run as soon as an actor appears (or spawns) on a scene, so it doesn't need a condition/rule. Have a rule that destroys the actor and also changes game.EnemyCount to game.EnemyCount-1. The only caveat is that I've had to add a timer ("after 0.1 seconds") to the rule so that the level doesn't change right when the scene opens. Have a control actor or background actor or HUD that has the rule If game.EnemyCount=0, Change Scene . The nice thing about this setup is that it works with 1 enemy or 100 enemies because each enemy that appears increases the count and then again decreases the count when it is destroyed.

    For a countdown timer, have a game attribute called CountdownTimer (integer) set to 5. Have an actor with a rule: If game.CountdownTimer>0 then... add a timer behavior "every 1 second" Change Attribute game.CountdownTimer=game.CountdownTimer-1. Add a Display Text behavior with game.CountdownTimer as the expression. If you want the scene to change after 5 seconds, have another rule that says If game.CountdownTimer=0, Change Scene .

    I haven't tested the count down timer, so you might have to make it If Game.CountdownTimer<=0, Change Scene <next scene>, but you probably can get the idea of it.

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

  • triton13triton13 Member Posts: 161
    Thank you very much guys. I will try this in a little bit and if I have any trouble I will let you know. =)
  • triton13triton13 Member Posts: 161
    I have never made attributes before but I think I might have figured it out except for the last part where if it equals 0 then change scene. How do I go about doing that?
  • triton13triton13 Member Posts: 161
    Never mind, I think I figured that out but I made a mistake somewhere with the attributes and putting them with the enemy and adding and subtracting them. Could someone help me with this? Like I said, I have never messed with attributes before and I need to start learning about them. Thanks
  • tatiangtatiang Member, Sous Chef, PRO, Senior Sous-Chef Posts: 11,949
    edited February 2012
    If you want to get up to speed on attributes and more, you can follow my video tutorial from start to finish to create a working game: If you just want to go straight to the solution, see this video included in that playlist:

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

  • triton13triton13 Member Posts: 161
    I did everything in the video and when I go to test it to see if it worked. It takes me to my scene that it's supposed to go to when all the actors are destroyed. It goes to it as soon as I preview it my first scene then it switches on me. =(
  • tatiangtatiang Member, Sous Chef, PRO, Senior Sous-Chef Posts: 11,949
    Did you include a timer, as I mentioned above? At 2:30 in the video, I add the rule without a timer. I recommend a timer to wrap around that rule. The other thing you can do is to include a Log Debugging Statement with the value "game.EnemyCount" wrapped in a timer set to every 0 seconds. Open the debugging window and watch to see if your enemy count starts at 0, goes up to some number, and then decreases back to 0. If that isn't happening, you need to fix your rules.

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

  • triton13triton13 Member Posts: 161
    I'm sorry but I'm a little confused
  • tatiangtatiang Member, Sous Chef, PRO, Senior Sous-Chef Posts: 11,949
    Confused about the debugger? If so, this will help: http://forums.gamesalad.com/discussion/39114. If not, post a screenshot of your rules and we can go from there.

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

  • triton13triton13 Member Posts: 161
    I'm a little confused about the timer thing. I don't have that in my game.
  • tatiangtatiang Member, Sous Chef, PRO, Senior Sous-Chef Posts: 11,949
    I'm not sure how to help you because you're just saying you're confused. It you want help, you'll need to post your rules so I have a better idea of what you're trying to do.

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

  • triton13triton13 Member Posts: 161
    Under my actors that I want to get destroyed then go to the next level when they are all gone, this is what I have. First off, I have an attribute, lets call it enemy and it's an integer. Under my "Enemy" actor I have Change Attribute game.Enemy to game.Enemy+1. I have a rule under that, that says, Actor receives event-touch is pressed then destroy actor. In that same rule under destroy actor I have Change Attribute game.Enemy to game.Enemy-1. Then on my background actor, I have a rule that says, Attribute-game.Enemy=0 and under that I have Change Scene. What am I doing wrong? It doesn't change scenes and like I said before, I play the first scene and it automatically switches to the other scene when I start it. I was confused about the timer thing that you were talking about so I don't know what to do. =/
  • tatiangtatiang Member, Sous Chef, PRO, Senior Sous-Chef Posts: 11,949
    edited February 2012
    So two things... (1) try moving the change attribute behavior above the destroy behavior just in case that's affecting the outcome. (2) The timer can be important here. Without a timer, and because GameSalad runs behaviors and rules in parallel to each other (at the same time), what can happen is that your scene loads and for a brief instant there are no enemies on the screen, so game.Enemy is 0. After that brief instant, the enemies appear and increase game.Enemy to however many enemies are on that scene. But because of the rule that I suggested to change the scene, you game is changing the scene right away. To avoid this, add a timer... here, I'll just post a picture:

    image

    The 0.5 second timer is there to allow the enemies time to appear/spawn and correctly increase game.Enemy to whatever number it should be. You can use any value... 1 second, 2 seconds, etc. but it needs to be less than however long you think it will take for someone to beat that level. I usually use 0.1 or 0.5 seconds.

    The log debugging statements will tell you a little about what's happening if it still isn't working for you. That or just add a Display Text actor with game.Enemy as the value for the text and add it to your scene so you can watch what's happening with that attribute.

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

  • triton13triton13 Member Posts: 161
    Alright, that helped out a lot. Thank you very much. Now I just new to figure out how to add that countdown timer so when the time runs out it changes to a specific scene.
Sign In or Register to comment.