Register to post in forums, or Log in to your existing account
 

Play RetroMUD
Post new topic  Reply to topic     Home » Forums » CMUD General Discussion
mawebr
Newbie


Joined: 28 Oct 2009
Posts: 4

PostPosted: 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?
Reply with quote
orphean
Apprentice


Joined: 21 Oct 2008
Posts: 147
Location: Olympia, WA

PostPosted: 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.
Reply with quote
MattLofton
GURU


Joined: 23 Dec 2000
Posts: 4834
Location: USA

PostPosted: 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
Reply with quote
Zugg
MASTER


Joined: 25 Sep 2000
Posts: 23379
Location: Colorado, USA

PostPosted: 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.
Reply with quote
charneus
Wizard


Joined: 19 Jun 2005
Posts: 1876
Location: California

PostPosted: 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
Reply with quote
mawebr
Newbie


Joined: 28 Oct 2009
Posts: 4

PostPosted: 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.
Reply with quote
Display posts from previous:   
Post new topic   Reply to topic     Home » Forums » CMUD General Discussion All times are GMT
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum

© 2009 Zugg Software. Hosted by Wolfpaw.net