|
mawebr Newbie
Joined: 28 Oct 2009 Posts: 4
|
Posted: Wed Oct 28, 2009 4:20 pm
%addItem |
I have a trigger, that when fired performs this...
Code: |
%additem( %2, @cList) |
where cList is a string list type variable, and %2 is a single word. The problem that I am having is that instead of adding the word to the variable list, it instead sends that word directly to the mud. I have tried %concat with the same error.
Any ideas? |
|
|
|
orphean Apprentice
Joined: 21 Oct 2008 Posts: 147 Location: Olympia, WA
|
Posted: Wed Oct 28, 2009 5:18 pm |
%additem returns a new list with the new item added, it doesn't modify the original list. The trigger should do this instead:
Code: |
cList = %additem(%2, @cList) |
Since %additem is returning the new list it will get sent to the mud if its called by itself just like anything else that isn't a command/function would. |
|
|
|
MattLofton GURU
Joined: 23 Dec 2000 Posts: 4834 Location: USA
|
Posted: Wed Oct 28, 2009 5:36 pm |
Functions (more accurately, anything that begins with % or @) return a result to the entity that called them. Commands (anything that starts with the number sign, or aliases), simply execute and send stuff to the game.
In your specific case, %additem() returns the new stringlist consisting of the old stringlist (@cList) plus the addition (%2). Since you didn't assign it to anything, the result is lost and @cList never gets %2 added to it. |
|
_________________ EDIT: I didn't like my old signature |
|
|
|
Zugg MASTER
Joined: 25 Sep 2000 Posts: 23379 Location: Colorado, USA
|
Posted: Wed Oct 28, 2009 5:48 pm |
So, you could also use the #ADDITEM command instead:
#ADDITEM cList %2
which is the most efficient way to add an item to a list and modify the list. This is faster than using the %additem function. |
|
|
|
charneus Wizard
Joined: 19 Jun 2005 Posts: 1876 Location: California
|
Posted: Wed Oct 28, 2009 7:07 pm |
Zugg wrote: |
So, you could also use the #ADDITEM command instead:
#ADDITEM cList %2
which is the most efficient way to add an item to a list and modify the list. This is faster than using the %additem function. |
Unless, of course, you're needing to add duplicates, in which case you'll need to use %additem. Otherwise, #ADDITEM is definitely better.
Charneus |
|
|
|
mawebr Newbie
Joined: 28 Oct 2009 Posts: 4
|
Posted: Wed Oct 28, 2009 7:25 pm |
Thank-you so much. I will try this when I get home. I am indeed using duplicates in a list, I had used #ADDITEM and it worked perfectly but with duplicates %additem is my only choice. Appreciate it.
|
|
|
|
|
|