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
thd
Beginner


Joined: 04 Mar 2005
Posts: 10

PostPosted: Sun Feb 05, 2006 8:52 am   

How to add a string into a string list in a random position
 
#var test {s|sw|e|se|su|enter|w}
What I want is to add "hello" into this string list in a random position, like:
{s|sw|hello|e|se|su|enter|w} or
{s|sw|e|se|su|enter|hello|w}, etc, so that each time run "#exec @test", I will say "hello" in a different room.
I know that #additem or %additem can only add a new string into the beginning or the end of a string list.
I didn't find a useful command or function to do this. So, have to:
#exec %replace(%insert("|hello|",@test,%random(2,%len(@text))),||,|)
but sometimes "hello" will seperate "sw" or "enter"..., like "..ent|hello|er|...".

Any way to do this ?
Reply with quote
Vijilante
SubAdmin


Joined: 18 Nov 2001
Posts: 5182

PostPosted: Sun Feb 05, 2006 6:28 pm   
 
#var test {s|sw|e|se|su|enter|w}
test=%replace(@test,"|","||")
test=%replaceitem(@test,%eval(%random(2,%numitems(@test))/2*2),"hello")
#DELITEM test {}

That should do it. The way it works is add a blank item between every other item, then randomly selects and mathematically changes that to an even number. Replacing an even numbered item with your hello. Then deletes out all the blank items.
_________________
The only good questions are the ones we have never answered before.
Search the Forums
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