String lists and the such

by Unknown

Back to Mechanic's Corner.

Unknown2007-06-02 10:59:16
I was just wondering if someone might be able to explain string lists and how they work for zMud. as well as the %eval() commands, and the whole additem, delitem, etc and so forth. I have always been wondering that, I learned a ton of the functions on my own, but I have never really been able to easily understand the way zMud help files explain things. Anyone have any idea on how to help me with this little issue?
Unknown2007-06-02 12:01:37
A string list variable is a list of strings separated by a | delimiter. When you use #ADDITEM on a variable, it tacks a string onto the end of the list, but only if it's not already on the list. When you use #DELITEM on a variable, it removes the string from the list, no matter where it is in the ordering. The %additem function is useful for adding multiple copies of a string, and it returns the newly updated string list as it's return value. %delitem has similar functionality.

CODE
#VAR test_list {one|two|three|something with spaces}
#ADDITEM test_list four
#ADDITEM test_list {another with spaces}
#DELITEM test_list {something with spaces}
#VAR test_list %additem(@test_list, one)
#VAR test_list %delitem(@test_list, "another with spaces")


The %eval function is just for forcing expansion of some expression. There are places in zScript where something like '@myvar - 20' would be treated as a literal string and just echo whatever's in @myvar and then ' - 20' behind it. You can put this inside a %eval call to subtract 20 from @myvar and return a numerical result.
Damadreas2007-06-03 04:20:16
Zarquan just made my head explode. But it somehow made sense. Can you give a realworld example of how this would be used though? Just so that I can truly wrap my head around the idea of -using- stringlists and such.
Ayridion2007-06-03 06:35:28
CODE
#var afflictions ""
#additem afflictions stupidity
#additem afflictions prone
#additem afflictions dementia

Afflictions variable is now "stupidity|prone|dementia"
CODE
#if (%ismember("stupidity",@afflictions)) {curestupidity}

Checks 'afflictions' stringlist and cures stupidity if 'stupidity' is in the variable.
CODE
#delitem afflictions prone
#delitem afflictions dementia

Afflictions variable is now "stupidity"
CODE
#delitem afflictions stupidity

Afflictions variable is now empty.
Gwylifar2007-06-03 14:53:07
Here's a very simple example of a good way to use a stringlist:

CODE
#var lUndersecretaries {Tom|Bob|Jane}
#alias msgundersecs {#forall @lUndersecretaries {msg %i Undersecretaries -> %-1}}


Easy way to send a message to all the people on a list.