[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]  Pluralising Variables

Home  |  Users  |  Search  |  FAQ
Username:
Register forum user name
Password:
Forgotten password?
(New message)
Subject: Pluralising Variables
Name:
Your forum user name.
Register forum user name
Password:
Your forum password.
Forgotten password?
Message:
Message to be posted (in English, please).
Forum codes:
Check this if your message uses 'forum codes' or templates (auto-detected for new posts).
Forum codes Templates

Save this message ...


Subject review (reverse sequence)

Posted by Nick Gammon   Australia  (18,772 posts)  [Biography] bio   Forum Administrator
Date Fri 22 Jul 2011 04:24 AM (UTC)  quote  ]

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
[Go to top] top

Posted by Neves   USA  (75 posts)  [Biography] bio
Date Fri 22 Jul 2011 03:51 AM (UTC)  quote  ]
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
[Go to top] top

Posted by Twisol   USA  (2,229 posts)  [Biography] bio
Date Thu 21 Jul 2011 04:48 AM (UTC)  quote  ]

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
[Go to top] top

Posted by Neves   USA  (75 posts)  [Biography] bio
Date Thu 21 Jul 2011 03:56 AM (UTC)  quote  ]
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
[Go to top] top

Posted by Nick Gammon   Australia  (18,772 posts)  [Biography] bio   Forum Administrator
Date Tue 19 Jul 2011 08:05 PM (UTC)  quote  ]
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
[Go to top] top

Posted by Fiendish   USA  (849 posts)  [Biography] bio   Global Moderator
Date Tue 19 Jul 2011 01:41 PM (UTC)  quote  ]
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

http://aardwolfclientpackage.googlecode.com/
[Go to top] top

Posted by Neves   USA  (75 posts)  [Biography] bio
Date Tue 19 Jul 2011 12:26 PM (UTC)  quote  ]
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
[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,166 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]