|
thd Beginner
Joined: 04 Mar 2005 Posts: 10
|
Posted: 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 ? |
|
|
|
Vijilante SubAdmin
Joined: 18 Nov 2001 Posts: 5182
|
Posted: 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 |
|
|
|
|
|
|
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
|
|