Counting time between lines

Posted by Svet on Sat 09 Mar 2013 08:37 AM — 10 posts, 34,604 views.

#0
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?
Australia Forum Administrator #1
Make two triggers?

http://www.gammon.com.au/scripts/doc.php?lua=utils.timer
#2
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?
USA Global Moderator #3
Quote:
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.
Amended on Sat 09 Mar 2013 06:01 PM by Fiendish
#4
I tested my triggers and they do fire.
USA Global Moderator #5
Good. Now try using SetVariable/GetVariable instead of local variables.
Australia Forum Administrator #6
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?


How do you know? How did you display the variables?
#7
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.
USA Global Moderator #8
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>


Amended on Sun 10 Mar 2013 04:17 PM by Fiendish
Australia Forum Administrator #9
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.


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