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
➜ Pluralising Variables
It is now over 60 days since the last post. This thread is closed.
Refresh page
Posted by
| Neves
USA (78 posts) Bio
|
Date
| Tue 19 Jul 2011 12:26 PM (UTC) |
Message
| I'm looking for a way to have an alias take the value in a variable, say @var, and create @varplural with it in plural form.
Since English plurals are complicated, I need it to check if the last consonant in @var is an s, if it is add es to the end, if not just add s. Also there are the words that are both plural and not, how would I write an exception list for the alias? Like exclude (boots, pants, trousers, etc?).
Thanks,
Neves | Top |
|
Posted by
| Fiendish
USA (2,535 posts) Bio
Global Moderator |
Date
| Reply #1 on Tue 19 Jul 2011 01:41 PM (UTC) |
Message
| probably the simplest way is to construct a table with the form
exceptions_table = {boots=true, pants=true, trousers=true}
And then check for exceptions by doing
if exceptions_table[@var] then
|
https://github.com/fiendish/aardwolfclientpackage | Top |
|
Posted by
| Nick Gammon
Australia (23,158 posts) Bio
Forum Administrator |
Date
| Reply #2 on Tue 19 Jul 2011 08:05 PM (UTC) |
Message
| Inside an alias you actually want:
if exceptions_table["@var"] then
And if you have just set that variable in the same alias this is needed:
if exceptions_table[GetVariable ("var")] then
|
- Nick Gammon
www.gammon.com.au, www.mushclient.com | Top |
|
Posted by
| Neves
USA (78 posts) Bio
|
Date
| Reply #3 on Thu 21 Jul 2011 03:56 AM (UTC) |
Message
| OK, and how would I check a string to see if the last letter is an 's' or not to decide if the plural is to add an 's' or 'es' (i.e. glass should be changed to glasses, chair would be changed to chairs).
Also, does anyone know if such a list of exceptions to the plural rule exists anywhere, or do I have to write my own?
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?
Thanks,
Neves | Top |
|
Posted by
| Twisol
USA (2,257 posts) Bio
|
Date
| Reply #4 on Thu 21 Jul 2011 04:48 AM (UTC) Amended on Thu 21 Jul 2011 04:49 AM (UTC) by Twisol
|
Message
|
Neves said: OK, and how would I check a string to see if the last letter is an 's' or not to decide if the plural is to add an 's' or 'es' (i.e. glass should be changed to glasses, chair would be changed to chairs).
if string.sub("@var", -1) == "s" then
-- ...
end
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
Yes, if you have save_state="y" in your plugin's <plugin> tag. This only works for MUSHclient variables (i.e. GetVariable/SetVariable), not Lua script variables.
Neves said: , or send the plugin to someone else?
Not exactly. The plugin's saved state is stored separately (you can view it by double-right-clicking the plugin in the plugins list). If you want to send that along with the plugin, you can. |
'Soludra' on Achaea
Blog: http://jonathan.com/
GitHub: http://github.com/Twisol | Top |
|
Posted by
| Neves
USA (78 posts) Bio
|
Date
| Reply #5 on Fri 22 Jul 2011 03:51 AM (UTC) |
Message
| I want to do this within the MUSHClient alias system, does the if string.sub work inside an alias or only for a plugin? Also how would I have it match the last word in a string instead of just the last letter?
Neves | Top |
|
Posted by
| Nick Gammon
Australia (23,158 posts) Bio
Forum Administrator |
Date
| Reply #6 on Fri 22 Jul 2011 04:24 AM (UTC) Amended on Fri 22 Jul 2011 04:25 AM (UTC) by Nick Gammon
|
Message
|
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+$")
|
- 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.
24,311 views.
It is now over 60 days since the last post. This thread is closed.
Refresh page
top