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

Play RetroMUD
Post new topic  Reply to topic     Home » Forums » zMUD General Discussion
Bobert
Beginner


Joined: 01 Apr 2004
Posts: 20
Location: Purdue University

PostPosted: Thu Mar 03, 2005 1:09 am   

#ADD to a specific possition within a string list
 
I'm trying to add values to a certain possition in a string list. I use this list based on the possition of the maximum value.

Here is what I'm working with:

#VAR list {0|0|0|0|0|0} //<- standard list
%pos( %max( %expandlist( @list, ",")), @list) //<- function that returns the possition of the maximum value. I use this as #IF (%pos( %max( %expandlist( @list, ",")), @list)=3) {action} for example

I can't figure out a way to add to a specific possition within that list. I'd like to have something along these lines, but how to pull it off escapes me.
Output: Bill kicks your dog
Result: #VAR list {+1|0|0|0|0|0}

Output: Jamie kicks your cat
Result #VAR list {0|+1|0|0|0|0}

That way I can check whether my dog or cat has been kicked more with:
#IF (%pos( %max( %expandlist( @list, ",")), @list)=3) {#echo Cat has been kicked more}

The closest way I can come up with is this, based of my string list experience:
#MATH list {list.1}+1
#ADD {list.1} 1
Reply with quote
MattLofton
GURU


Joined: 23 Dec 2000
Posts: 4834
Location: USA

PostPosted: Thu Mar 03, 2005 2:13 am   
 
You already know the position of the stringlist you want to modify, right? Simply %eval() this information using %item(stringlist,itemnumber) to refer to the appropriate item and you can then directly substitute that with %replaceitem() into your stringlist.

%replaceitem(%eval(%item(stringlist,itemnumber) + 1), itemnumber, stringlist)
_________________
EDIT: I didn't like my old signature
Reply with quote
Bobert
Beginner


Joined: 01 Apr 2004
Posts: 20
Location: Purdue University

PostPosted: Thu Mar 03, 2005 2:16 am   
 
I think I solved my own problem, sorry to bother you all.

#AL checkpet {#IF (%pos( %max( %expandlist( @list, ",")), @list)=1) {#echo Dog has been kicked more}} {#IF ((%pos( %max( %expandlist( @list, ",")), @list)=3)) {#echo Cat has been kicked more}}
#VAR list {@dog|@cat|@otheritem}
#VAR dog {0} {0}
#TR {%w kicks your dog} {#ADD dog 1}
#TR {%w kicks your cat} {#ADD cat 1}

and such.
Thanks for giving me a place to think. =P

edit: If there's a reason I shouldn't approach it this way, please let me know.
Reply with quote
Display posts from previous:   
Post new topic   Reply to topic     Home » Forums » zMUD 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