[Home] [Downloads] [Search] [Help/forum]

Gammon Forum

See www.mushclient.com/spam for dealing with forum spam. Please read the MUSHclient FAQ!

[Folder]  Entire forum
-> [Folder]  MUSHclient
. -> [Folder]  Lua
. . -> [Subject]  Setting an int-variable
Home  |  Users  |  Search  |  FAQ
Username:
Register forum user name
Password:
Forgotten password?

Setting an int-variable

It is now over 60 days since the last post. This thread is closed.     [Refresh] Refresh page


Posted by tobiassjosten   Sweden  (79 posts)  [Biography] bio
Date Mon 25 Apr 2005 05:51 PM (UTC)
Message
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>

Simplicity is Divine | http://nogfx.org/
[Go to top] top

Posted by Larkin   (278 posts)  [Biography] bio
Date Reply #1 on Mon 25 Apr 2005 06:25 PM (UTC)
Message
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+)$
[Go to top] top

Posted by tobiassjosten   Sweden  (79 posts)  [Biography] bio
Date Reply #2 on Mon 25 Apr 2005 06:43 PM (UTC)
Message
Worked like a charm, thanks alot! Now, to mix balances into this..

Simplicity is Divine | http://nogfx.org/
[Go to top] top

Posted by tobiassjosten   Sweden  (79 posts)  [Biography] bio
Date Reply #3 on Mon 25 Apr 2005 07:44 PM (UTC)
Message
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?

Simplicity is Divine | http://nogfx.org/
[Go to top] top

Posted by Flannel   USA  (1,230 posts)  [Biography] bio
Date Reply #4 on Mon 25 Apr 2005 08:02 PM (UTC)

Amended on Mon 25 Apr 2005 08:05 PM (UTC) by Flannel

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

~Flannel

Messiah of Rose
Eternity's Trials.

Clones are people two.
[Go to top] top

Posted by tobiassjosten   Sweden  (79 posts)  [Biography] bio
Date Reply #5 on Mon 25 Apr 2005 08:05 PM (UTC)

Amended on Tue 26 Apr 2005 05:26 AM (UTC) by tobiassjosten

Message
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).

Simplicity is Divine | http://nogfx.org/
[Go to top] top

The dates and times for posts above are shown in Universal Co-ordinated Time (UTC).

To show them in your local time you can join the forum, and then set the 'time correction' field in your profile to the number of hours difference between your location and UTC time.


5,986 views.

It is now over 60 days since the last post. This thread is closed.     [Refresh] Refresh page

Go to topic:           Search the forum


[Go to top] top

Quick links: MUSHclient. MUSHclient help. Forum shortcuts. Posting templates. Lua modules. Lua documentation.

Information and images on this site are licensed under the Creative Commons Attribution 3.0 Australia License unless stated otherwise.

[Home]


Written by Nick Gammon - 5K   profile for Nick Gammon on Stack Exchange, a network of free, community-driven Q&A sites   Marriage equality

Comments to: Gammon Software support
[RH click to get RSS URL] Forum RSS feed ( https://gammon.com.au/rss/forum.xml )

[Best viewed with any browser - 2K]    [Hosted at FutureQuest]