Reset Time Problem

Hello there Gamesalad Community!

I have a problem on an app I'm developing and would like to get some of your help.

My game is sort of like the one that is very popular in the AppStore at the moment called Llama or Duck?

Soooooo my problem is in the main gameplay, when the images are randomly switching around every 1 second, if I happen to press a button that summons the next picture it so happens that the timer doesn't 'reset' and the image that comes next doesn't stay on the screen as long as it normally would.

Anybody know how I can reset the timer? If this helps, I have a boolean attribute that triggers whenever you get the name of the animal right with the animal on the image and is untriggered after 0.01 seconds.

Thank you for your time!

Comments

  • tatiangtatiang Member, Sous Chef, PRO, Senior Sous-Chef Posts: 11,949
    @TheShatteredBox, when you post a problem you are having, it's almost always necessary to see your actual rules. Without them, we would just be guessing and not very helpful.
  • TheShatteredBoxTheShatteredBox Member Posts: 21
    Oh ok! Here they are:
    there are 2 animals, 6 images for each of them(tigers and lions)
    rule for the random spawner:
    every 1 second
    change attribute game.spawner to random(1,12)<------12 images

    Tiger button
    when touch is pressed and game.spawner is either 1,2,3,4,5 or 6

    change attribute trueT to true<----- trueT is the boolean attribute for the tiger button

    when trueT is true
    destroy either tiger1,2,3,4,5 or 6 and add +1 to game.score

    same goes for the lion button and images

    If there is anything left you may need please tell me.If you find the problem please tell me too!
  • tatiangtatiang Member, Sous Chef, PRO, Senior Sous-Chef Posts: 11,949
    edited January 2013
    Your timer doesn't have a condition (e.g. when game.trueT=true) so it just keeps firing every second regardless of whether or not the button was pressed.

    What currently is happening is that if you press the button 1 second after the random number is generated, it destroys the tiger (although why not just recycle it by moving it to a new position or giving it a new image?) and chooses a new number immediately. But if you press the button 0.9 seconds after the random number is generated, the timer fires again 0.1 seconds later to choose a new number.

    Here's the algorithm I would use:

    choose random image
    change attribute game.timeStamp (real) to self.Time
    If self.TIme>game.timeStamp+1 [this is the every 1 second timer without a timer behavior] OR game.trueT=true:
    .....choose random image
    .....change attribute game.timeStamp (real) to self.Time


  • TheShatteredBoxTheShatteredBox Member Posts: 21
    Thank you! Still didn't get it to work for one simple reason, and that is that I don't understand what you mean in choose random image. Can you please be more specific? Thanks!
  • tatiangtatiang Member, Sous Chef, PRO, Senior Sous-Chef Posts: 11,949
    Okay, sorry. It's hard to tell how you have things set up because you didn't type your rules verbatim, but just summarized parts of them. I'm guessing then that you are spawning a different actor (with its own image) based on the random number?

    A better way to do this is to import images with their names 1.png, 2.png, 3.png, etc. and then do Change Image to game.spawner or whatever your random number attribute is.

    If that still doesn't make sense, just substitute "spawn new tiger button" for "choose random image" in my post above.
  • TheShatteredBoxTheShatteredBox Member Posts: 21
    Thanks! I do have that way of the 1.png setup. Still didn't understand what the 2nd choose random image meant... And also, in which actor do I type in those statements?
  • tatiangtatiang Member, Sous Chef, PRO, Senior Sous-Chef Posts: 11,949
    edited January 2013
    Llama/Duck actor
    choose random image initial image for the actor
    change attribute game.timeStamp (real) to self.Time "stamp" the current time
    *The two behaviors above are repeated within the rule below... the reason for their appearance above is because we want them to fire immediately rather than after one second has elapsed

    If self.TIme>game.timeStamp+1 [this is the every 1 second timer without a timer behavior] OR game.trueT=true: if one second has elapsed since "stamp" or button was pressed
    .....choose random image change the image for the actor
    .....change attribute game.timeStamp (real) to self.Time "stamp" the current timer
  • TheShatteredBoxTheShatteredBox Member Posts: 21
    Ok I'm starting to get it, but two last questions. Do I do this for both the tiger button and the lion button or just on the spawner? Because the spawner spawns the images, and the buttons turn on the trueT and trueL. Also, the choose random image for the trueT and trueL will be, respectively: random(1,6) and random(7,12) right? Sorry for the hassle...
Sign In or Register to comment.