Help with basic tempTimer syntax

Post Reply
Jarl
Posts: 5
Joined: Fri Jan 07, 2011 7:53 am

Help with basic tempTimer syntax

Post 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!

User avatar
Vadi
Posts: 5035
Joined: Sat Mar 14, 2009 3:13 pm

Re: Help with basic tempTimer syntax

Post by Vadi »

That syntax is right. Make sure that the function exists and does it's job properly?

User avatar
Heiko
Site Admin
Posts: 1548
Joined: Wed Mar 11, 2009 6:26 pm

Re: Help with basic tempTimer syntax

Post 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.

User avatar
Rakon
Posts: 350
Joined: Tue Feb 16, 2010 7:41 pm
Contact:

Re: Help with basic tempTimer syntax

Post 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.

User avatar
Heiko
Site Admin
Posts: 1548
Joined: Wed Mar 11, 2009 6:26 pm

Re: Help with basic tempTimer syntax

Post 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.

Jarl
Posts: 5
Joined: Fri Jan 07, 2011 7:53 am

Re: Help with basic tempTimer syntax

Post 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?

User avatar
Omni
Posts: 131
Joined: Fri Feb 12, 2010 10:26 am

Re: Help with basic tempTimer syntax

Post by Omni »

tonumber(quantity)

Post Reply