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


Joined: 27 Mar 2008
Posts: 106

PostPosted: Thu May 07, 2009 4:32 pm   

trying to pop a random action off a string list
 
Here are the basics of what I want to do:

Code:

#exec %random( %pop( masks))


That is not working, and I'm really not sure how to actually do that.
Its simple, @masks, is a string list with a lot of actions and I just want to throw one out there at random when a certain pattern comes at me from the mud.
Reply with quote
Fang Xianfu
GURU


Joined: 26 Jan 2004
Posts: 5155
Location: United Kingdom

PostPosted: Thu May 07, 2009 4:58 pm   
 
Your script doesn't really make sense.

Firstly, %pop removes the first item from the stringlist and returns it. It sounds like you don't want the item to be removed, just returned, but if that was the case, you'd then be passing that single item to %random. %random returns a random number, and expects a number range as its arguments, so passing it a string won't work.

In short, what you want is %item(@masks,%random(1,%numitems(@masks))). This will generate a random number between 1 and the number of items in @masks, and then return the item in that position in the list.
_________________
Rorso's syntax colouriser.

- Happy bunny is happy! (1/25)
Reply with quote
albo
Apprentice


Joined: 27 Mar 2008
Posts: 106

PostPosted: Thu May 07, 2009 5:13 pm   
 
Code:

#1 {%item( @masks, %random( 1, 65))}



Thanks Fang, i actually just clicked more help on the %random help file and used this straight from the example. Works fine, I'll test yours too see which I like best.
Reply with quote
Erasmus
Wanderer


Joined: 04 Aug 2004
Posts: 82
Location: Philadelphia

PostPosted: Thu May 07, 2009 5:27 pm   
 
I would go with Fang's. The difference is that you have hardcoded the number range the %random will check, while Fang's example is flexible. With his the range will automatically expand and contract to match the number of items in the masks variable (as long as there is at least 1).

Inferno
_________________
Erasmus

Last edited by Erasmus on Thu May 07, 2009 7:48 pm; edited 1 time in total
Reply with quote
albo
Apprentice


Joined: 27 Mar 2008
Posts: 106

PostPosted: Thu May 07, 2009 5:32 pm   
 
Well, there are only 65 actions in the string list variable.

Is there a way to perhaps make it put the the item that it chose from the list into another variable? This is a mask spell which changes my the name of my character randomly whenever the spell wears off, and I was wondering if by typing:

whoami

I could use:

Code:

#say You are currently masked as...@mask


That would be cool.
Reply with quote
charneus
Wizard


Joined: 19 Jun 2005
Posts: 1876
Location: California

PostPosted: Thu May 07, 2009 6:17 pm   
 
Sure can.


mask=%item(@masks,%random(1,%numitems(@masks)))
#EXEC @mask

#ALIAS whoami {#SAY "You are currently masked as... "@mask}

You can make it work however you want to.

Charneus
Reply with quote
albo
Apprentice


Joined: 27 Mar 2008
Posts: 106

PostPosted: Thu May 07, 2009 7:34 pm   
 
Cool, thanks a bunch everyone. It helps in PvP a lot, as they thought they were fighting Anna, but anna withdrew from combat and you see Isabelle cross your path and it can get confusing as you might have your targetting system locked on to Anna, and then isabelle jumps on you..
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