|
Joined: Oct 2011
Posts: 4
Self-satisified door
|
OP
Self-satisified door
Joined: Oct 2011
Posts: 4 |
So I'm trying to take a list of 12 objects, randomize it, and then display 3 at a time. I'm sorta a newb when it comes to scripting, so help would be appreciated. (player# are all just text strings edited for privacy reason) on *:TEXT:!newlines:*: {
set %newlines player1 player2 player3 player4 player5 player6 player7 player8 player9 player10 player11 player12
set %newlinecounter 1
while (%newlinecounter <= 12) {
set %newlinerand $rand(1,$numtok(%newlines,32))
echo -s $addtok(%newlinesdisp,$gettok(%newlines,%newlinecounter,32),32)
echo -s $deltok(%newlines,%newlinerand,32)
inc %newlinecounter 1
}
msg $chan $gettok(%newlinesdisp,1,32) - $gettok(%newlinesdisp,2,32) - $gettok(%newlinesdisp,3,32)
msg $chan $gettok(%newlinesdisp,4,32) - $gettok(%newlinesdisp,5,32) - $gettok(%newlinesdisp,6,32)
msg $chan $gettok(%newlinesdisp,7,32) - $gettok(%newlinesdisp,8,32) - $gettok(%newlinesdisp,9,32)
msg $chan $gettok(%newlinesdisp,10,32) - $gettok(%newlinesdisp,11,32) - $gettok(%newlinesdisp,12,32)
}
I have no idea why it isn't working, so any help is appreciated.
|
|
|
|
Joined: Oct 2004
Posts: 8,330
Hoopy frood
|
Hoopy frood
Joined: Oct 2004
Posts: 8,330 |
You can't use echo to add or remove tokens. It will echo what you are doing, but won't actually change any variables. Replace echo -s with set. Or, if you don't need these variables anywhere other than in this script, then change all set to var to make them local variables (they don't remain set after they aren't needed anymore). And, to make it easier on your message lines... before them, you can use:
tokenize 32 %newlinesdisp And then, for your message lines, you can use:
msg $chan $1 - $2 - $3
msg $chan $4 - $5 - $6 etc.
Invision Support #Invision on irc.irchighway.net
|
|
|
|
Joined: Oct 2011
Posts: 4
Self-satisified door
|
OP
Self-satisified door
Joined: Oct 2011
Posts: 4 |
Thanks it works now, also didn't help that I had the wrong variable in the addtok line d'oh.
|
|
|
|
Joined: Jul 2007
Posts: 1,129
Hoopy frood
|
Hoopy frood
Joined: Jul 2007
Posts: 1,129 |
on *:text:!newlines:#:{
var %newlines = player1 player2 player3 player4 player5 player6 player7 player8 player9 player10 player11 player12
tokenize 32 %newlines
var %r = 1, %i
while (%r <= $0) {
%i = %i $($+($,$rand(1,$0)),2)
inc %r
}
msg # $gettok(%i,1-3,32)
msg # $gettok(%i,4-6,32)
msg # $gettok(%i,7-9,32)
msg # $gettok(%i,10-12,32)
}
|
|
|
|
Joined: Feb 2006
Posts: 546
Fjord artisan
|
Fjord artisan
Joined: Feb 2006
Posts: 546 |
on *:text:!newlines:#:{
var %newlines = player1 player2 player3 player4 player5 player6 player7 player8 player9 player10 player11 player12
tokenize 32 %newlines
var %r = 1, %i
while (%r <= $0) {
%i = %i $($+($,$r(1,$0)),2)
inc %r
}
msg # $gettok(%i,1-3,32)
msg # $gettok(%i,4-6,32)
msg # $gettok(%i,7-9,32)
msg # $gettok(%i,10-12,32)
} nope. this just makes 12 random selections from %newlines, without replacement, that can and almost certainly will contain duplicates. if he wanted to make the code more efficient, he could use:
var %output
while (%newlinecounter <= 12) {
%output = $instok(%output, $gettok(%newlines, %newlinecounter, 32), $rand(1, %newlinecounter), 32)
inc %newlinecounter
}
then %output contains a scrambled version of %newlines.
"The only excuse for making a useless script is that one admires it intensely" - Oscar Wilde
|
|
|
|
Joined: Jul 2007
Posts: 1,129
Hoopy frood
|
Hoopy frood
Joined: Jul 2007
Posts: 1,129 |
Ouch. That makes sense, and thank you, jaytea.
|
|
|
|
Joined: Jun 2012
Posts: 1
Mostly harmless
|
Mostly harmless
Joined: Jun 2012
Posts: 1 |
how would the full script look lets say if i was trying to do 8 things and I wanted it to randomize all 8 things with no duplicates?
|
|
|
|
|