Problem with a timer

BasGoodboyBasGoodboy Member, PRO Posts: 310
Hey all,

So.. for my project I made a sleepbutton with a timer.. I made it with the next code:

Actor(button) named Sleep, which does:
When touch is pressed > spawn actor SleepAction.

Actor(invisible) named SleepAction, which does:
If gametimer is > 0, do, every 1 second, set gametimer to: gametimer-1.

The gametimer is an integer with value of 5 (5 seconds).

The timer works great. The button to press it too.

After the timer did his work (timer is actually visible on the stage with a 'timer' actor which shows the gametimer, comes the problem:

Whenever people are repressing the button 'Sleep', the timer will go a second faster, cause of the 'If gametimer is > 0, do, every 1 second, set gametimer to: gametimer-1'-rule.

So basically, people can skip the sleep by repressing and repressing sleep so it goes very fast. The idea is too have a slow sleep which make you have to wait in patience. Also, the same problem but in a different mode is if people did wait without clicking untill the sleep is over, if they want to sleep again the Creator will remember the first click and the second sleep will go a second faster too.

I hope you guys understand what I mean, any solutions?

Comments

  • The_Gamesalad_GuruThe_Gamesalad_Guru Member Posts: 9,922
    Make a self lockout Boolean that turns true after pressed and resets to false after the amount of time you want say when game timer =0
  • BasGoodboyBasGoodboy Member, PRO Posts: 310
    edited August 2013
    That makes sense, but..

    EDIT: done. See next answer plz.
  • The_Gamesalad_GuruThe_Gamesalad_Guru Member Posts: 9,922
    We're talking about logic right. So think it out logically. So we have a rule that when pressed starts the timer so we need to put that Boolean lockout in that condition sequence. Then when it's pressed and after the timer starts we need to change the Boolean so the button can't be pressed again. Then we need to change the Boolean back when the timer is a 0. So here is what that looks like. First don't spawn the actor there is no need to. Just put these rules in the actor being touched.

    Self attribute lockout (Boolean)

    Rule
    All
    When touch is pressed. When Attribute lockout is false. When attribute game timer > 0

    Timer

    Every 1.0.

    Change attribute game timer to game timer -1

    Timer. Run to completion checked

    After .3

    Change attribute self lockout to true


    New Rule
    All

    When attribute game timer = 0

    Change attribute self lockout to false

    Timer

    After .3

    Change attribute game timer to 5

  • BasGoodboyBasGoodboy Member, PRO Posts: 310
    My main question still is.. If a player press a button a timer of 5 seconds comes.. during this 5 seconds all other buttons are locked and the game will be in a sort of pauze mode.. then after this 5 seconds the timer is gone and people could press it again.

    The main problem is that if people click it for the second time or third time (even after the 5 seconds cooldown the button is on lock), Creator 'remembers' the clicks and since the timer goes on click -1second, it will go -2 seconds second click and -3 seconds third click and so on.

    Please help.
  • mataruamatarua Auckland, New ZealandMember Posts: 854
    Create an attribute called locked. It's boolean.

    Set locked to false or 0

    The button has a rule that surrounds the timer and two conditions:

    game.locked is false

    and

    Actor receives event - touch is released

    Change attribute

    game.locked to true

    Perform timer.

    Timer completes.

    Change attribute

    game.locked to false


    That locks and unlocks the button from being a button.
  • BasGoodboyBasGoodboy Member, PRO Posts: 310
    Thank u!!
  • The_Gamesalad_GuruThe_Gamesalad_Guru Member Posts: 9,922
    edited August 2013
    Didn't I just post working code? Why do I bother. I just showed you how to lock it out. you can make the self attribute a game level attribute and use it to lock out anything.
  • BasGoodboyBasGoodboy Member, PRO Posts: 310
    Sorry FryingBaconStudios, I looked over it or something, now I see it tho, you helped me a lot with it! Hope u forgive the late answer.
  • BasGoodboyBasGoodboy Member, PRO Posts: 310
    ..and it all works!
  • mataruamatarua Auckland, New ZealandMember Posts: 854
Sign In or Register to comment.