Setting an int-variable

Posted by tobiassjosten on Mon 25 Apr 2005 05:51 PM — 6 posts, 28,590 views.

Sweden #0
I'm having problem setting a numeric variable with LUA. If I leave out the "'s, it complains that the variable is nil. If I include them, it says it's a string. I need it to be an int-type variable, how can I do this?

Code:
<alias
   match="^pres (?P&lt;amount&gt;.*?) (?P&lt;toxin&gt;.*?)$"
   enabled="y"
   regexp="y"
   send_to="12"
   omit_from_output="y"
   sequence="100"
  >
  <send>presToxin = "%&lt;toxin&gt;"
presAmount = "%&lt;amount&gt;"
print("Preserving:", presToxin, " (", presAmount, ")")
world.Send ("prepare toxin ", presToxin)</send>
  </alias>
#1
You can set an integer variable easily. I think the error message you got may have been referring to your call to world.Send (and the "world." part is optional in Lua, which is one reason I like it).

You use .. to concatenate strings in Lua, so try changing your print and Send commands to use that instead of commas. Convert numbers to strings (for concatenation, for example) with the tostring() function.


presToxin = "%&lt;toxin&gt;"
presAmount = %&lt;amount&gt;
print("Preserving: " .. presToxin .. " (" .. tostring(presAmount) .. ")")
Send("prepare toxin " .. presToxin)


You might also want to change your regular expression to match more specifically a number and then a string:


^pres (?P&lt;amount&gt;\d+) (?P&lt;toxin&gt;\w+)$
Sweden #2
Worked like a charm, thanks alot! Now, to mix balances into this..
Sweden #3
Remade the whole plugin to work more off of LUA functions. Debuged and removed most of the errors, but I just can't seem to find what's causing: [string "Trigger: "]:1: `=' expected near `<eof>'

The plugin is up at: http://www.crox.org/cxPreserve.xml

Could anyone more experienced with LUA please help me decipher this?
USA #4
Your first trigger should have &lt; &gt; instead of brackets, but that's just an annoyance (can't view in webbrowser).

When are you getting that error?
Amended on Mon 25 Apr 2005 08:05 PM by Flannel
Sweden #5
I get it whenever the plugin calls presPrompt.

Edit: Removed annoyance.. ;)

Edit2: Fixed it by adding () after the function calls. Now I get another error..
[string "Trigger: "]:1: attempt to call global `presPrepared' (a nil value)
stack traceback:
	[string "Trigger: "]:1: in main chunk

Not sure if I get it when presPrepared is called, or when presPrompt is called. I'm still trying to learn.. Is this a good way of setting up a plugin?

Edit3: Now it's fully operational again, with added balance checks. Tried to call my functions from the send-part of the triggers, which I think Larkin said was oogley (didn't work that well either).