I want to count the time (in seconds) between two lines, which appear in my output window, and then store it in a variable. The counter should start at the first line, then stop and store the elapsed time at the second line. How do I do this?
Counting time between lines
Posted by Svet on Sat 09 Mar 2013 08:37 AM — 10 posts, 34,604 views.
This is what I did, but it still doesn't work:
<triggers>
<trigger
enabled="y"
expand_variables="y"
match="^([[:alpha:]]+) brings back (her|his) arm\, locking eyes with you"
regexp="y"
send_to="12"
sequence="100"
>
<send>check_fury = utils.timer ()</send>
</trigger>
</triggers>
<triggers>
<trigger
enabled="y"
match="^([[:alpha:]]+) hurls ([[:alpha:]]+) at you\, which returns to (her|his) hand\. You"
regexp="y"
send_to="12"
sequence="100"
>
<send>time_fury = utils.timer () - check_fury</send>
</trigger>
</triggers>
The variables don't get the new values. Can you help me?
<triggers>
<trigger
enabled="y"
expand_variables="y"
match="^([[:alpha:]]+) brings back (her|his) arm\, locking eyes with you"
regexp="y"
send_to="12"
sequence="100"
>
<send>check_fury = utils.timer ()</send>
</trigger>
</triggers>
<triggers>
<trigger
enabled="y"
match="^([[:alpha:]]+) hurls ([[:alpha:]]+) at you\, which returns to (her|his) hand\. You"
regexp="y"
send_to="12"
sequence="100"
>
<send>time_fury = utils.timer () - check_fury</send>
</trigger>
</triggers>
The variables don't get the new values. Can you help me?
Quote:
This is what I did, but it still doesn't work:
This is what I did, but it still doesn't work:
Do your triggers fire at all? That's the first step, but we can't tell from what you wrote.
I tested my triggers and they do fire.
Good. Now try using SetVariable/GetVariable instead of local variables.
Svet said:
This is what I did, but it still doesn't work:
...
The variables don't get the new values. Can you help me?
This is what I did, but it still doesn't work:
...
The variables don't get the new values. Can you help me?
How do you know? How did you display the variables?
To Nick Gammon: I tested the triggers a few times with different time interval between them. After each test, I glanced at World Properties... > Scripting > Variables to see the value of my variables, but they always stood with the default value.
I updated my triggers and now I use SetVariable/GetVariable as Fiendish suggested. I did a test with my triggers as follows:
<triggers>
<trigger
enabled="y"
match="^([[:alpha:]]+) brings back (her|his) arm\, locking eyes with you"
regexp="y"
send_to="12"
sequence="100"
>
<send>SetVariable ("check_fury", "utils.timer ()")
DoAfter (math.floor (GetVariable ("time_fury") - 0.5), "duck")</send>
</trigger>
</triggers>
<triggers>
<trigger
enabled="y"
match="^([[:alpha:]]+) hurls ([[:alpha:]]+) at you\, which returns to (her|his) hand\. You"
regexp="y"
send_to="12"
sequence="100"
>
<send>SetVariable ("time_fury", "utils.timer () - check_fury")</send>
</trigger>
</triggers>
During this test my "check_fury" variable updated with "utils.timer ()" value and my "time_fury" variable remained unchanged. Then, I removed the quotes:
<triggers>
<trigger
enabled="y"
match="^([[:alpha:]]+) brings back (her|his) arm\, locking eyes with you"
regexp="y"
send_to="12"
sequence="100"
>
<send>SetVariable ("check_fury", utils.timer ())
DoAfter (math.floor (GetVariable ("time_fury") - 0.5), "duck")</send>
</trigger>
</triggers>
<triggers>
<trigger
enabled="y"
match="^([[:alpha:]]+) hurls ([[:alpha:]]+) at you\, which returns to (her|his) hand\. You"
regexp="y"
send_to="12"
sequence="100"
>
<send>SetVariable ("time_fury", utils.timer () - check_fury)</send>
</trigger>
</triggers>
This time my "check_fury" variable updated with "128839.22926007" value and my "time_fury" variable remained unchanged again.
I updated my triggers and now I use SetVariable/GetVariable as Fiendish suggested. I did a test with my triggers as follows:
<triggers>
<trigger
enabled="y"
match="^([[:alpha:]]+) brings back (her|his) arm\, locking eyes with you"
regexp="y"
send_to="12"
sequence="100"
>
<send>SetVariable ("check_fury", "utils.timer ()")
DoAfter (math.floor (GetVariable ("time_fury") - 0.5), "duck")</send>
</trigger>
</triggers>
<triggers>
<trigger
enabled="y"
match="^([[:alpha:]]+) hurls ([[:alpha:]]+) at you\, which returns to (her|his) hand\. You"
regexp="y"
send_to="12"
sequence="100"
>
<send>SetVariable ("time_fury", "utils.timer () - check_fury")</send>
</trigger>
</triggers>
During this test my "check_fury" variable updated with "utils.timer ()" value and my "time_fury" variable remained unchanged. Then, I removed the quotes:
<triggers>
<trigger
enabled="y"
match="^([[:alpha:]]+) brings back (her|his) arm\, locking eyes with you"
regexp="y"
send_to="12"
sequence="100"
>
<send>SetVariable ("check_fury", utils.timer ())
DoAfter (math.floor (GetVariable ("time_fury") - 0.5), "duck")</send>
</trigger>
</triggers>
<triggers>
<trigger
enabled="y"
match="^([[:alpha:]]+) hurls ([[:alpha:]]+) at you\, which returns to (her|his) hand\. You"
regexp="y"
send_to="12"
sequence="100"
>
<send>SetVariable ("time_fury", utils.timer () - check_fury)</send>
</trigger>
</triggers>
This time my "check_fury" variable updated with "128839.22926007" value and my "time_fury" variable remained unchanged again.
It looks like you're complicating things a bit. Going back to what you originally posted, try this modification...
<triggers>
<trigger
enabled="y"
expand_variables="y"
match="^([[:alpha:]]+) brings back (her|his) arm\, locking eyes with you"
regexp="y"
send_to="12"
sequence="100"
>
<send>SetVariable("check_fury", utils.timer())</send>
</trigger>
</triggers>
<triggers>
<trigger
enabled="y"
match="^([[:alpha:]]+) hurls ([[:alpha:]]+) at you\, which returns to (her|his) hand\. You"
regexp="y"
send_to="12"
sequence="100"
>
<send>time_fury = utils.timer() - GetVariable("check_fury"))</send>
</trigger>
</triggers>
Svet said:
To Nick Gammon: I tested the triggers a few times with different time interval between them. After each test, I glanced at World Properties... > Scripting > Variables to see the value of my variables, but they always stood with the default value.
To Nick Gammon: I tested the triggers a few times with different time interval between them. After each test, I glanced at World Properties... > Scripting > Variables to see the value of my variables, but they always stood with the default value.
You don't have to use get and set variable, but you do need to understand about the different types of variables.
http://www.gammon.com.au/forum/?id=10863