Reseting the Timer when actor is destroyed

themagicboxthemagicbox Member, PRO Posts: 82
I would like to know if there was a behavior to reset a timer...in my game there are multiple actors
when the game starts the player can touch any of the actors to destroy them..the player will have to eventually destroy all the actors by touching them...when the first actor is destroyed..a timer starts and after 5 seconds it triggers another action (ill call it t.action for this example)...now when another actor is destroyed after that first initial one that started the timer, and every actor destroyed after that by touch, the timer will reset back to 0 and start again...i am trying to get t.action to happen whenever no actors have been destroyed after 5 seconds...but if the player was to constantly destroy each actor under 5 seconds, t.action would never happen

Comments

  • The_Gamesalad_GuruThe_Gamesalad_Guru Member Posts: 9,922
    edited April 2013
    Use self.time

    So in your actor that controls the events that trigger.

    Game level attribute Integer (t.action)
    Self attribute in event actor Real (start.time)
    Self attribute in actor interger (fired)

    Rule

    Self.time > 0 Game.t.action = 1

    Change attribute self.start.time to self.time

    Rule inside this rule.

    Self.start.time > 0 Self.time > self.start.time+5

    Do action

    Change attribute self.fired to 1


    New rule outside of rules above.

    Self.time > 0 Game.t.action = 2 Self.fired = 1

    Change attribute self.start.time to self.time

    Rule inside

    Self.time > self.start.time + 5

    Do action

    Change attribute self.fired to 2

    Just add more rules like the second I called new rule and just adjust the numbers game.t.action and self.fired and at the end reset the self.start.time attribute to 0.
  • themagicboxthemagicbox Member, PRO Posts: 82
    Wow thank you so much!!!!, but I'm not going to lie its going to take some time to grasp whats going on there lol...I just hope it works when I try it out ....I'm still tryin to understand self.time...from what I can figure out at the end there when fire is changed to 2...that means self.fire (which is the action I want to trigger) will happen with the Internet is 2? And when it's one it just means it in the middle of a timer?
  • themagicboxthemagicbox Member, PRO Posts: 82
    Integer*
  • The_Gamesalad_GuruThe_Gamesalad_Guru Member Posts: 9,922
    edited April 2013
    Self.time is calculated by the processor and starts when the actor appears on the scene. So think of the start.time we are using of a snapshot of the self.time clock at the moment the rule starts. Then we just measure the time that passes here we are doing 5 seconds and we wait to start the next timer until the next event is ready. And the integer tells the rules when the last timer finished so they fire in a straight logical order. Hope that helps. Where I wrote DO ACTION is where you would insert your behaviors for the actions you want to happen. You can keep adding rule timers and just count up with the integer.
  • themagicboxthemagicbox Member, PRO Posts: 82
    haha so i couldnt figure out the way you showed me but i came up with another way that seems to be working so far (if you have a feeling there may be something wonky with the code let me know but it seems to be working well...

    what i did is this....so each actor has a boolean attribute (isdead1, isdead2, isdead3) that becomes true when it the actor is destroyed

    when an actor is destroyed for the first time i have a trigger actor off screen that sets a start.self.time attribute to self.time...when self.time = start.self.time+2...start t.action
    This trigger actor also has conditional rules for when each actor on screen gets destroyed and sets it boolean (isdead) to true
    Now whenever an isdead attribute becomes true, start.self.time gets set at the current self.time, thus making the condition for t.action to happen (if self.time = start.self.time+2) unmet and the t.action has not happened yet.

    if all actors are destroyed the trigger actor gets destroyed and t.action will never happen in that scene unless reset.
  • The_Gamesalad_GuruThe_Gamesalad_Guru Member Posts: 9,922
    Sounds perfect. Sometimes it's just about steering people's mind in a direction to think about the issue differently and work it out with their own solution.
Sign In or Register to comment.