How to make a table match enable a timer....

Posted by Walton on Fri 19 Jun 2009 09:21 PM — 7 posts, 24,053 views.

#0

table = table or {}
if table["%1"] and not table["%2"] then
EnableTimer("timer",true)
end


The above format will work if I try to send a command rather than enable something...but how can I use a table match to enable another timer or trigger?
Australia Forum Administrator #1
You want to enable a timer if something is in a table, and something else is not in it?

What you have should work. You may want to reset the timer to make it start from scratch again.

http://www.gammon.com.au/scripts/doc.php?function=ResetTimer
#2
You're right. That wasn't the problem..

In another part of the script I have the same thing with the variables reversed, and it does not work.

example here:

table = table or {}
if table["%2"] and not table["%1"] then
EnableTimer("timer",true)
end


Shouldn't the above work too?
Australia Forum Administrator #3
Yes it should. I would point out that "table" is a Lua table of functions. See:

http://www.gammon.com.au/scripts/doc.php?general=lua_tables

Thus, using "table" as the name of your table might cause confusion.

In code like this:


if table["%2"] and not table["%1"] then
  EnableTimer("timer",true)
end


I would point in some debugging code.

For example:


print ("%%1 is '%1', %%2 is '%2'")
if table["%2"] and not table["%1"] then
  print ("enabling timer")
  EnableTimer("timer",true)
else
  print ("test failed")
end


This shows that you are executing the code in the first place, and whether the test fails or not.
#4
Thanks for the response. I didn't actually use table as the name of the table, only in the example. The code did work on someone else's mushclient.....and our settings were set the same as far as I could tell. I'll see if I can get anything out of the debugging code but I'm confused as to what is happening.
#5
here's what the debugging code is telling me:

The %1 is correct, the %2 is correct... but it's still failing.

It fires only if the code reads ["%1"] before ["%2"].
Australia Forum Administrator #6
Well, do you ever clear out the items from the table?