Page 1 of 1

Help with basic tempTimer syntax

Posted: Fri Jan 07, 2011 8:10 am
by Jarl
I am really new to scripting, and have been working on my lua and enjoying the learning, but I have recently run into a problem.

I do not understand the syntax for tempTimer. I can get a simple tempTimer to work such as

tempTimer(2,[[echo("It has been two seconds")]]) to work, but when i try something like

tempTimer(15,[[purchaseReagent()]]), does not fire at all. Is there a different syntax to calling functions than echo's or send's?

Also, it would be helpful to know how to use the Batch Timer and the Offset timers mentioned in the Manual, but I can find no documentation on their use. Am I just being silly and missing something simple?

Thanks in advance for the help!

Re: Help with basic tempTimer syntax

Posted: Fri Jan 07, 2011 9:21 am
by Vadi
That syntax is right. Make sure that the function exists and does it's job properly?

Re: Help with basic tempTimer syntax

Posted: Fri Jan 07, 2011 9:36 am
by Heiko
One of the most important buttons in Mudlet is the red ! error view button on the left side of the trigger editor. It'll report Lua runtime errors of your scripts.

Re: Help with basic tempTimer syntax

Posted: Fri Jan 07, 2011 2:05 pm
by Rakon
Regarding Lua errors: Is there a way I can have ALL errors printed to the main Mudlet profile window, instead of that minconsole in the scripting/editor dialog?? Is there an event that is raised on errors with the information, so that I can call my own function to echo to screen on an error?? IF not, could we please have this functionality added in?? Thanks.

Re: Help with basic tempTimer syntax

Posted: Fri Jan 07, 2011 11:57 pm
by Heiko
Rakon wrote:Is there an event that is raised on errors with the information, so that I can call my own function to echo to screen on an error?? IF not, could we please have this functionality added in?? Thanks.
I think that there's an option to log errors. In any case I'll add the error events idea.

Re: Help with basic tempTimer syntax

Posted: Sat Jan 08, 2011 2:44 am
by Jarl
Thank you for the help, I figured out the problem to be bad scripting on my part. I needed to assign a variable to the reagent type I was buying so it would persist (rather than allowing "matches[2]" to go through to the function).

Now I have another problem however. I have an alias as follows:
Code: [show] | [select all] lua
^buyreagent (\d+) (\w+)$ 
quantity=matches[2]
reagentType=matches[3]
enableTrigger("Purchase Reagents")
purchaseReagent()
This calls the purchase and enables a trigger that does the following:
Code: [show] | [select all] lua
if quantity > "0" then  -- the zero is in quotes because of the problem I am trying to fix.
	tempTimer(15,[[purchaseReagent()]])
	tempTimer(15,[[echo("you should purchase another "..reagentType)]])
	quantity=quantity-1
	echo("Starting purchase, you have "..quantity.." more to purchase.")
else echo("PURCHASE COMPLETE!")
	disableTrigger("Purchase Reagents")
	send("inr 50 reagent")
end
When I call the alias without the zero in quotes, I get an error that says the trigger is trying to match a number with a string. When I put the zero in quotes, the trigger fires properly once, then gives me the same error. It seems as though they variable type changes from string to number or number to string... is there a way I can force it to be a number through the alias and remain a number?

Re: Help with basic tempTimer syntax

Posted: Sat Jan 08, 2011 7:06 am
by Omni
tonumber(quantity)