mIRC Home    About    Download    Register    News    Help

Print Thread
#92061 29/07/04 04:19 AM
Joined: Jul 2004
Posts: 3
M
micah Offline OP
Self-satisified door
OP Offline
Self-satisified door
M
Joined: Jul 2004
Posts: 3
hi everyone,
this code is used for a trivia game based on replacing a random word in a sentence.
i have the number of words set to eight but i would like it to be any amount up to 14 with the words being random and not the first 14 that are eligible.
it works the way it is but i have to check each sentence to make sure there are at least 8 eligible words to prevent a lockup.
i can't figure out the while statement.
thank you in advance to anyone that can help.

var %i = 1
var %qwn = $numtok(%qwords,32)
while (%qwn < 8) {
var %qw = $gettok(%quote,$rand(3,$numtok(%quote,160)),160)
if (!$istok(%qwords,%qw,32)) && ($len(%qw) > 3) { set %qwords $addtok(%qwords,%vw,32) | set %qwp $+ %i $findtok(%quote,%qw,160) | inc %qwn | inc %i }
}
quote-start
}




#92062 29/07/04 04:09 PM
Joined: Apr 2004
Posts: 7
P
Nutrimatic drinks dispenser
Offline
Nutrimatic drinks dispenser
P
Joined: Apr 2004
Posts: 7
I can't think straight because I just got up and am half asleep but you should have it check with if ($8) and then carry on (or however you specifiy a word for it.)


-----
"No tears please, it's a waste of good suffering" --Pinhead
#92063 29/07/04 06:56 PM
Joined: Jul 2004
Posts: 3
M
micah Offline OP
Self-satisified door
OP Offline
Self-satisified door
M
Joined: Jul 2004
Posts: 3
the first post was too hard to read, lines were jumbled.
any help please with setting number to 14 random words?

var %i = 1
var %qwn = $numtok(%qwords,32)
while (%qwn < 8) {
var %qw = $gettok(%quote,$rand(3,$numtok(%quote,160)),160)
if (!$istok(%qwords,%qw,32)) && ($len(%qw) > 3) { do commands here}
}
quote-start
}

#92064 29/07/04 08:20 PM
Joined: Feb 2003
Posts: 282
S
Fjord artisan
Offline
Fjord artisan
S
Joined: Feb 2003
Posts: 282
I still don't have any idea what you wanna do.

Can you give an example?

Tell us whats are the words in the list that can be randomned.

Give us an example of a sentance, and then give an example to what you want that will happened.

#92065 29/07/04 08:51 PM
Joined: Dec 2002
Posts: 1,245
M
Hoopy frood
Offline
Hoopy frood
M
Joined: Dec 2002
Posts: 1,245
eally hard to tell without seeing the rest of the code, but:
Code:
 
var %i = 1
var %qwn = $numtok(%qwords,32)
if (%qwn &gt; 14) { var %qwn = 14 }
while (%i &lt;= %qwn) {
 

should help avoid lockup

#92066 29/07/04 10:13 PM
Joined: Jul 2004
Posts: 3
M
micah Offline OP
Self-satisified door
OP Offline
Self-satisified door
M
Joined: Jul 2004
Posts: 3
sorry for the confusion on the code, changed it up a little.

var %i = 1
var %qwn = $numtok(%qwords,32)
while (%qwn < 8) {
var %qw = $gettok(%quote,$rand(3,$numtok(%quote,160)),160)
if (!$istok(%qwords,%qw,32)) && ($len(%qw) > 3) {
set %qwords $addtok(%qwords,%vw,32)
set %qwp $+ %i $findtok(%quote,%qw,160)
inc %qwn
inc %i
}
}
quote-start
}
if this example is used for %quote
Peter_Benchley Jaws The great fish moved silently through the night water, propelled by short sweeps of its crescent tail.
once it is passed to quote-start the 8 random words are converted to
Peter_Benchley Jaws The ***** **** moved ******** through the night *****, ********* by ***** ****** of its ******** tail.
the problem is many of the quotes have less than 8 eligible words, some have over 25.
i would like to use any %quote without having to check if there are at least 8 eligible words but limit the total to say 14 random words chosen from %quote
the %i variable is used to get the place in the %quote string where that word occurs so if someone guesses the word it will be replaced with the word instead of *****.
thank you to those that have responded and to anyone that can help

#92067 30/07/04 05:36 AM
Joined: Aug 2003
Posts: 314
S
Fjord artisan
Offline
Fjord artisan
S
Joined: Aug 2003
Posts: 314
The following is an example of a way to accomplish this to replace N amount of random words using $reprand(string,N)

alias reprand {
var %i = $2,%used
tokenize 32 $1
while (%i) {
var %rand = $r(1,$0)
if ($istok(%used,%rand,32)) { continue }
else { tokenize 32 $iif(%rand != 1,$($+($,1-,$calc(%rand -1)),2)) $str(*,$len($($ $+ %rand,2))) $($+($,$calc(1+%rand),-),2) }
%used = $addtok(%used,%rand,32)
dec %i
}
return $1-
}

This loops N amount of times and picks a random token in the string. It replaces that token with a series of *s using /tokenize providing that it hasn't already been replaced

#92068 30/07/04 06:24 PM
Joined: Feb 2003
Posts: 282
S
Fjord artisan
Offline
Fjord artisan
S
Joined: Feb 2003
Posts: 282
Nice work. smile
You might wanna add another function which will handle the number N, so when you get a string, the number N will be decided by the string itself to prevent lockup, and to prevent N from being greater than 14 (like he whishes).

alias n-return {
var %a = $numtok($1,32)
var %a = $ceil($calc(%a /2))
if (%a > 14) %a = 14
return %a
}

This way N will always be smaller (or equals, in the worst case) than the number of tokens.

Now you use:
$reprand(string,$n-return(string))

You can change the $calc(%a /2) to what ever you want, like $calc(%a *2/3) in order to get a little more random tokens.


Link Copied to Clipboard