Problem with a timer
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?
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
EDIT: done. See next answer plz.
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
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.
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.