Neves said:
Third, if I have a variable in a plugin, does it save whatever information it was changed to after I loaded it it even if I close the plugin and reload it, or send the plugin to someone else?
As Twisol said, if you have save_state set to "y" then MUSHclient variables are saved, per world. This isn't fabulously useful for sending to someone else because they'll have different world file IDs.
For distributing data, a couple of options would be:
- Serialize the variables into a string (see: http://www.gammon.com.au/forum/?id=4960) and then write that string to a text file (you could open it with io.open, write to it, close it).
- Use a SQLite3 database (see: http://www.gammon.com.au/db). This lets you share things (eg. mob names) between multiple worlds as the same database could be opened by many worlds. Also you could send the database to someone else.
Neves said:
I want to do this within the MUSHClient alias system, does the if string.sub work inside an alias or only for a plugin?
Yes, the Lua libraries work inside aliases if you set the language to Lua and do "send to script".
Neves said:
Also how would I have it match the last word in a string instead of just the last letter?
One way is to use a regular expression, and find a word (ie %a+) anchored to the end of the target string, like this:
test = "Every good boy deserves fruit"
last_word = string.match (test, "%a+$")
print (last_word) --> fruit
Note that since the % symbol has a special meaning inside alias "send" boxes, you need to double it if you are using send to script, ie.
last_word = string.match (test, "%%a+$")
|