10 Mar 11, 03:13AM
Timestamps, as in checking to see if the current command being executed after a sleep actually belongs. Since you can't cancel a script, any sleep will still be running if you zoomin then out quickly. If the sequence is not completed, the sleep will still be running and the sleep will awake (couldn't find better word) in the middle of something important. Use timestamps like GD did with the vote recall/cancel script. I'll draw a timeline to explain it:
This is normal behaviour:
sleep 1
>time>>>>>>>>>>>>>>>>>>>
|----------------------------------------------------------|
some alias ("+" = 1, "-" = 0), which is only supposed to execute at the end of the sleep if it is "0"
|++++++++++++++++|----------------------------|
but when the sequence isn't allowed to execute fully
sleep
>time>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
|----------------------------------------------------------|
some alias ("+" = 1, "-" = 0), which is only supposed to execute at the end of the sleep if it is "0"
|++++++(break)-----------------(start over)++++++| oh noes I'm not executed
Vote recall script:
This is normal behaviour:
sleep 1
>time>>>>>>>>>>>>>>>>>>>
|----------------------------------------------------------|
some alias ("+" = 1, "-" = 0), which is only supposed to execute at the end of the sleep if it is "0"
|++++++++++++++++|----------------------------|
but when the sequence isn't allowed to execute fully
sleep
>time>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
|----------------------------------------------------------|
some alias ("+" = 1, "-" = 0), which is only supposed to execute at the end of the sleep if it is "0"
|++++++(break)-----------------(start over)++++++| oh noes I'm not executed
Vote recall script:
[SELECT ALL] Code:
// Reset the aliases just in case
cancelallvotes = [ votingno = 0; votingyes = 0; votetimestamp = 0]
cancelallvotes
vote_exec1 = [ vote 1; echo "0You voted yes"; cancelallvotes ]
vote_exec2 = [ vote 2; echo "3You voted no"; cancelallvotes ]
// $arg1 = millis
delayed_vote = [
// only bother if we're actually due
if (= ($votetimestamp) ($arg1) ) [
if (= ($votingyes) 1) [ vote_exec1 ]
if (= ($votingno) 1) [ vote_exec2 ]
] [
echo "All this wait for nothing..."
]
]
delayed_vote_start = [ votetimestamp = (millis); sleep 5000 [ delayed_vote votetimestamp ] ]
delayvote1 = [
if (= ($votingyes) 1) [
// voting yes when already have voted yes, do it immediately
vote_exec1
] [
if (= ($votingno) 1) [
// changed mind, cancel
echo "6You cancelled your F2"; cancelallvotes
] [
// normal/first vote
echo "Voting YES in five seconds!"; votingyes = 1; delayed_vote_start
]
]
]
delayvote2 = [
if (= ($votingno) 1) [
// voting no when already have voted no, do it immediately
vote_exec2
] [
if (= ($votingyes) 1) [
// changed mind, cancel
echo "6You cancelled your F1"; cancelallvotes
] [
// normal/first vote
echo "Voting NO in five seconds!"; votingno = 1; delayed_vote_start
]
]
]
bind "F1" [delayvote1]
bind "F2" [delayvote2]