Random

by Kharaen

Back to Mechanic's Corner.

Kharaen2007-01-15 18:25:36
I want to make some random buttons.

From what I understand you make a variable with the options in it, then use %random (1,n) to get a random response?

So if I used this:

#var emotes {bow|hug|salute|shake}
#alias ranemo {@emotes{%random(1,4)}

It'd do a random emote in the list?
ferlas2007-01-15 18:33:47
CODE

#var emotechoice=0
#alias {randomemote} {
emotechoice = %random( 1, 3)
#IF (emotechoice =1) {hug @target}
#IF (emotechoice=2) {slap @target}
#IF (emotechoice=3) {kick @target}
}


?
Unknown2007-01-15 18:46:14
#alias thank_you_for_not_snuggling %item("hug|snuggle|lick",%random(1,3))
Soll2007-01-15 18:50:54
QUOTE(Kharaen d'Attai @ Jan 15 2007, 06:25 PM) 373653

I want to make some random buttons.

From what I understand you make a variable with the options in it, then use %random (1,n) to get a random response?

So if I used this:

#var emotes {bow|hug|salute|shake}
#alias ranemo {@emotes{%random(1,4)}

It'd do a random emote in the list?


A few syntax errors in yours. The below will work.
CODE

#var emotes {bow|hug|salute|shake}
#alias ranemo {#1 {%item( @emotes, %random( 1, %numitems( @emotes)))}}


The above would work better, since it'd automatically pick one of any of the items in the 'emotes' variable, even if you add more. But essentially, yes, it works like that.
Unknown2007-01-15 19:17:38
You don't need to do a loop of one iteration. You could use #EXEC instead. Other than that, I'd go with Soll's code.
Kharaen2007-01-15 19:29:03
Thanks! And no, it's not for snuggling tongue.gif
Soll2007-01-15 21:28:58
Eh, it was a toss up between #exec and #1, so I just went for the one that was shorter. I was in a rush. tongue.gif But yes.