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

Gammon Software Solutions forum

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

[Folder]  Entire forum
-> [Folder]  MUSHclient
. -> [Folder]  General
. . -> [Subject]  Using Variables

Home  |  Users  |  Search  |  FAQ
Username:
Register forum user name
Password:
Forgotten password?

Using Variables

[Reply to this subject]  Reply to this subject   [New subject]  Start a new subject   [Refresh] Refresh page


Posted by Rynok   USA  (25 posts)  [Biography] bio
Date Wed 21 Jan 2009 03:32 AM (UTC)  quote  ]
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.
[Go to top] top

Posted by Nick Gammon   Australia  (18,769 posts)  [Biography] bio   Forum Administrator
Date Reply #1 on Wed 21 Jan 2009 04:50 AM (UTC)  quote  ]
Message
See http://mushclient.com/faq point 31.

- Nick Gammon

www.gammon.com.au, www.mushclient.com
[Go to top] top

Posted by Rynok   USA  (25 posts)  [Biography] bio
Date Reply #2 on Thu 22 Jan 2009 05:06 AM (UTC)  quote  ]
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.
[Go to top] top

Posted by Nick Gammon   Australia  (18,769 posts)  [Biography] bio   Forum Administrator
Date Reply #3 on Thu 22 Jan 2009 05:39 AM (UTC)  quote  ]
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
[Go to top] top

Posted by Rynok   USA  (25 posts)  [Biography] bio
Date Reply #4 on Fri 23 Jan 2009 03:15 AM (UTC)  quote  ]
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.
[Go to top] top

Posted by Nick Gammon   Australia  (18,769 posts)  [Biography] bio   Forum Administrator
Date Reply #5 on Fri 23 Jan 2009 03:52 AM (UTC)  quote  ]
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
[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.


1,303 views.

[Reply to this subject]  Reply to this subject   [New subject]  Start a new subject   [Refresh] Refresh page

Go to topic:           Search the forum


[Go to top] top

[Home]

Written by Nick Gammon - 5K

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

[Best viewed with any browser - 2K]    [Internet Contents Rating Association (ICRA) - 2K]    [Web site powered by FutureQuest.Net]