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
Jaerin
Apprentice


Joined: 10 Oct 2000
Posts: 132
Location: USA

PostPosted: Fri Jan 18, 2002 7:02 am   

Stringlist issues
 
Okay I'm trying to find an eligant solution to a problem that I could fudge to work. There has got to be a better way to do this:

given:

sumlist = ghast3|ghast2|ghast

problem:

trigger fires when I summon a new ghast. I want to turn the above stringlist into the following:

ghast4|ghast3|ghast2|ghast

Problem isn't so simple though...the list isn't always only going to have ghasts in it. For example:

ghast|werewolf|hellhound

Summon another ghast and I want the list to look like:

ghast2|werewolf|hellhound|ghast


Here is what I've tried so far:



#if (%ismember( ghast, @sumlist)) {
#var sumlist {%replaceitem( ghast4, %ismember( ghast3, @sumlist), @sumlist)}
#var sumlist {%replaceitem( ghast3, %ismember( ghast2, @sumlist), @sumlist)}
#var sumlist {%replaceitem( ghast2, %ismember( ghast1, @sumlist), @sumlist)}
#var sumlist {%replaceitem( ghast1, %ismember( ghast, @sumlist), @sumlist)}
#var sumlist {%additem( ghast, @sumlist)}
} {
#var sumlist {%additem( ghast, @sumlist)}
}


Works great with one major flaw. %replace doesn't like it when you give it a position of 0. Like when the %ismember returns 0 because the item doesn't exist. It totally hoses your list. So I suppose I could nest each of the above statements in it's own %ismember if, but I think there has to be a better way to do it. So let me know if you can think of anything.




#if (%ismember( ghast, @sumlist)) {
#if (%ismember( ghast3, @sumlist)) {#var sumlist {%replaceitem( ghast4, %ismember( ghast3, @sumlist), @sumlist)}}
#if (%ismember( ghast2, @sumlist)) {#var sumlist {%replaceitem( ghast3, %ismember( ghast2, @sumlist), @sumlist)}}
#if (%ismember( ghast1, @sumlist)) {#var sumlist {%replaceitem( ghast2, %ismember( ghast1, @sumlist), @sumlist)}}
#if (%ismember( ghast, @sumlist)) {#var sumlist {%replaceitem( ghast1, %ismember( ghast, @sumlist), @sumlist)}}
#var sumlist {%additem( ghast, @sumlist)}
} {
#var sumlist {%additem( ghast, @sumlist)}
}


Well this works great the first 2 times then I run into a really wierd problem that might be a bug in the beta. List looks great through the first 2 iterations, but on the third the list gets munched. Here's what the list looks like when the trigger fires the first few times:

First:

ghast

Second:

ghast1|ghast

Third:

ghast2ghast1|ghast


Not sure why it's getting munched like that but I submitted a bug report.

Thanks

Jaerin
Reply with quote
Troubadour
GURU


Joined: 14 Oct 2000
Posts: 556
Location: USA

PostPosted: Fri Jan 18, 2002 9:25 am   
 
I couldn't figure out what was wrong with your second script, sorry. I wrote this alternative though. It steps through the list looking for a mob similar to the one you're adding, extracts and increments the number then concatenates the old stringlist onto the back of the new item.



#ALIAS addghast {
#VAR n 0
#VAR mob ""
#UNTIL (%pos(%1, @mob) OR (@n > %numitems(@sumlist))) {
#ADD n 1
#VAR mob %item(@sumlist, @n)
}
#IF (@n <= %numitems(@sumlist)) {
#VAR num %if(%isnumber(%rightback(@mob, 1)), %eval(%rightback(@mob, 1) + 1), 1)
} {
#VAR num ""
}
#VAR sumlist %concat(%1,@num,"|",@sumlist)
}


I wrote it so you can add any variety of mob, but if you want to make it ghast-specific, replace both occurrences of %1 with "ghast".

Troubadour
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