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 ➜ Suggestions ➜ Variables in scripts

Variables in scripts

You need to log onto the forum to reply or create new threads.

  Refresh page


Posted by Errigour   USA  (35 posts)  Bio
Date Thu 17 Jul 2025 08:17 AM (UTC)
Message
I really think it would be a good idea to allow you to use
expand variables when making aliases or triggers etc.. to
define and use variables. Idk if there is a way to do that
without using SetVariable and GetVariable. Like if you use say
@myvariable = 1 and it doesn't exist it should make that
variable. That would be really cool I believe mudlet does
something similar to that accept they just make all your lua
variables part of the worlds variables and then delete them on
close unless you check them with a check box. Thanks for
letting me waste your time.

Example:
@myvariable = 1

if @myvariable == 1 then
-- do something
end
Top

Posted by Nick Gammon   Australia  (23,162 posts)  Bio   Forum Administrator
Date Reply #1 on Thu 17 Jul 2025 09:04 PM (UTC)
Message
There is already something similar to that supplied with MUSHclient. See: https://www.gammon.com.au/forum/?id=4904&reply=6#reply6

You have to put "var." in front of variables that you want saved, eg.


var.gold = 666

print (var.hp)  --> might be nil


This basically uses a Lua table called "var" which is automatically serialized (you still have to save your world file to save the variables).

So, there isn't much difference between putting "@" at the start of the variable you want saved, and putting "var.". You could edit the plugin and make "var" be "v" if you want to save typing.


Quote:

That would be really cool I believe Mudlet does something similar to that accept they just make all your Lua variables part of the worlds variables and then delete them on close unless you check them with a check box.


Well, you could make it that you have a table of variables you want saved, and then automatically serialize those.

For serializing, see: https://www.gammon.com.au/forum/?id=4960

- Nick Gammon

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

Posted by Errigour   USA  (35 posts)  Bio
Date Reply #2 on Fri 18 Jul 2025 11:41 AM (UTC)
Message
This gives an error but I have a variable called cutter.


if var.cutter == "1" then
  Note("No Longer Boarding Cutter.")
  var.cutter = "0"
else
  Note("Boarding Cutter.")
  var.cutter = "1"
end



Run-time error
World: Ethius on Necromium
Immediate execution
[string "Alias: "]:1: attempt to index global 'var' (a nil value)
stack traceback:
        [string "Alias: "]:1: in main chunk
Top

Posted by Errigour   USA  (35 posts)  Bio
Date Reply #3 on Fri 18 Jul 2025 11:44 AM (UTC)

Amended on Fri 18 Jul 2025 11:49 AM (UTC) by Errigour

Message
Oh I see what I did wrong, next time I need to read the posts you suggest first. Ok thanks.
Top

Posted by Fiendish   USA  (2,540 posts)  Bio   Global Moderator
Date Reply #4 on Tue 22 Jul 2025 04:11 PM (UTC)

Amended on Tue 22 Jul 2025 04:13 PM (UTC) by Fiendish

Message
Nobody should ever use the feature to expand "@" variables inside a script body. It's just a bad idea because the expansion happens before the script is actually run and it inevitably leads to confusion and broken code. The only safe use is for dynamic match patterns.

https://github.com/fiendish/aardwolfclientpackage
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,999 views.

You need to log onto the forum to reply or create new threads.

  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.