|
Joined: Jul 2004
Posts: 3
Self-satisified door
|
OP
Self-satisified door
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 }
|
|
|
|
Joined: Apr 2004
Posts: 7
Nutrimatic drinks dispenser
|
Nutrimatic drinks dispenser
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
|
|
|
|
Joined: Jul 2004
Posts: 3
Self-satisified door
|
OP
Self-satisified door
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 }
|
|
|
|
Joined: Feb 2003
Posts: 282
Fjord artisan
|
Fjord artisan
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.
|
|
|
|
Joined: Dec 2002
Posts: 1,245
Hoopy frood
|
Hoopy frood
Joined: Dec 2002
Posts: 1,245 |
eally hard to tell without seeing the rest of the code, but:
var %i = 1
var %qwn = $numtok(%qwords,32)
if (%qwn > 14) { var %qwn = 14 }
while (%i <= %qwn) {
should help avoid lockup
|
|
|
|
Joined: Jul 2004
Posts: 3
Self-satisified door
|
OP
Self-satisified door
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
|
|
|
|
Joined: Aug 2003
Posts: 314
Fjord artisan
|
Fjord artisan
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
|
|
|
|
Joined: Feb 2003
Posts: 282
Fjord artisan
|
Fjord artisan
Joined: Feb 2003
Posts: 282 |
Nice work.  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.
|
|
|
|
|