Register forum user name Search FAQ

Gammon Forum

Notice: Any messages purporting to come from this site telling you that your password has expired, or that you need to verify your details, confirm your email, resolve issues, making threats, or asking for money, are spam. We do not email users with any such messages. If you have lost your password you can obtain a new one by using the password reset link.

Due to spam on this forum, all posts now need moderator approval.

 Entire forum ➜ MUSHclient ➜ General ➜ Using Variables

Using Variables

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


Posted by Rynok   USA  (25 posts)  Bio
Date Wed 21 Jan 2009 03:32 AM (UTC)
Message
I've been looking over the website but for the life of me can't figure out how to use a variable.

All I've found is how to access one via "Expand Variables".
What I need to do is increment a variable (var + 1).
It keeps storing it as a string, and doing it via a script makes it fail like crazy (and seems like the long way around to me).

I think I'm just missing something that should be very simple.
Top

Posted by Nick Gammon   Australia  (23,133 posts)  Bio   Forum Administrator
Date Reply #1 on Wed 21 Jan 2009 04:50 AM (UTC)
Message
See http://mushclient.com/faq point 31.

- Nick Gammon

www.gammon.com.au, www.mushclient.com
Top

Posted by Rynok   USA  (25 posts)  Bio
Date Reply #2 on Thu 22 Jan 2009 05:06 AM (UTC)
Message
Isn't that still all handled inside a script though?
I was hoping there was a way to do the arithmetic inside MUSHclient itself.

Similar to the example: 'xp = xp + 1' except when I've done this inside the client itself, it would look like 'xp = @xp + 1' and when I do that, it treats it like a string so that 'xp' actually equals "@xp + 1" (instead of adding it like I'm wanting it to do).

Thanks for the help.
Top

Posted by Nick Gammon   Australia  (23,133 posts)  Bio   Forum Administrator
Date Reply #3 on Thu 22 Jan 2009 05:39 AM (UTC)
Message
I'm not too sure what you mean by "inside the client". The script engine is inside the client, particularly Lua, which is imbedded into it.

There is no specific provision for adding 1 to a variable in the GUI interface (after all, someone would want to add 2, or multiply by 3 or something). Thus ad-hoc arithmetic is done by scripting.

It isn't hard, you make a trigger like:


Match: something happens
Send: xp = xp + 1
Send to: script


However that is adding to a script variable. If you want to add to a MUSHclient variable (which would be saved with the world file), you change it to:


Match: something happens
Send: SetVariable ("xp", GetVariable ("xp") + 1)
Send to: script



- Nick Gammon

www.gammon.com.au, www.mushclient.com
Top

Posted by Rynok   USA  (25 posts)  Bio
Date Reply #4 on Fri 23 Jan 2009 03:15 AM (UTC)
Message
Hmm, so you don't need to make a function call? I figured scripts needed a function to be called to do everything. (I made a function, but it kept failing. I do Lua a lot, so I was doing it in that, but didn't see why it was failing. It might of been because I was giving a function name inside the "Script" field after having it "Send to script" as well)

On second thought, I need the default to always be 0, so having it saved with the World on exit wouldn't do me any good. I was hoping to make a quick one and not work with scripting, but if I can do the inline scripting like that then that'll accomplish the same task.

Anyways, I'll give it a go and see where I get.

Thanks again.
Top

Posted by Nick Gammon   Australia  (23,133 posts)  Bio   Forum Administrator
Date Reply #5 on Fri 23 Jan 2009 03:52 AM (UTC)
Message
If you do "send to script" whatever is in the send box is compiled into a Lua "chunk" and then executed. Therefore it needs (to be useful) to be Lua code (not just declarations). That code might declare a function, but ultimately you need to execute it.

If you want the default to be zero (per session) then as suggested earlier, this idiom works quite well in Lua:


xp = (xp or 0) + 1


That makes sure that xp (which is nil when the engine is started up) is replaced by zero the first time around.

- Nick Gammon

www.gammon.com.au, www.mushclient.com
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.


18,325 views.

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

Go to topic:           Search the forum


[Go to top] top

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