This is the new home of the egghelp.org community forum.
All data has been migrated (including user logins/passwords) to a new phpBB version.


For more information, see this announcement post. Click the X in the top right-corner of this box to dismiss this message.

Random Number Text

Help for those learning Tcl or writing their own scripts.
Post Reply
User avatar
kris
Voice
Posts: 14
Joined: Tue Sep 12, 2006 10:46 am
Location: Perth, Australia
Contact:

Random Number Text

Post by kris »

it sets it, and does most of it but it doesnt reply to the number, any ideas?

Thanks for your help guys :)

Code: Select all

bind pub "-|-" `numbers msg_number 
proc msg_number { nick host hand chan text } {
putquick "PRIVMSG $chan :\00307\002\037(\037\002\00304$nick has started The Number Guessing Game.\00307\037\002)"
putquick "PRIVMSG $chan :\00307\002\037(\037\002\00304The Number Range is From:\002 1 \002To:\002 50 \002\00307\037\002)"
putquick "PRIVMSG $chan :\00307\002\037(\037\002\00304To Guess What Number Type: `guess (Number)\002\00307\037\002)"
}
set number {
"\"1\""
"\"2\""
"\"3\""
"\"4\""
"\"5\""
"\"6\""
"\"7\""
"\"8\""
"\"9\""
"\"10\""
"\"11\""
"\"12\""
"\"13\""
"\"14\""
"\"15\""
"\"16\""
"\"17\""
"\"18\""
"\"19\""
"\"20\""
"\"21\""
"\"22\""
"\"23\""
"\"24\""
"\"25\""
"\"26\""
"\"27\""
"\"28\""
"\"29\""
"\"30\""
"\"31\""
"\"32\""
"\"33\""
"\"34\""
"\"35\""
"\"36\""
"\"37\""
"\"38\""
"\"39\""
"\"40\""
"\"41\""
"\"42\""
"\"43\""
"\"44\""
"\"45\""
"\"46\""
"\"47\""
"\"48\""
"\"49\""
"\"50\""
}
bind pub "-|-" `guess msg_guess
proc msg_guess { nick chan host handle text number } {
if {$number = $text} { putquick "PRIVMSG $chan :Congragulations, $nick, You Have Won!" }
if {$number != $text} {
if {$number > $text} { putquick "PRIVMSG $chan :This Is Bigger than the correct Number" }
if {$number < $text} { putquick "PRIVMSG $chan :This is Smaller than the correct Number" }
} else {
return
}
}
KrisDC Eggdrop Services - 2006
User avatar
rosc2112
Revered One
Posts: 1454
Joined: Sun Feb 19, 2006 8:36 pm
Location: Northeast Pennsylvania

Post by rosc2112 »

You could use rand to create the random number, I don't see anything in your script that actually selects any of the numbers from the $number list.

set number [rand 50]

(Hmm does rand ever select 0 as a number? Never checked on that..)

Then do the tests like:

if {$text == $number} {#exact match}
elseif {$text < $number} {# higher than}
elseif {$text > $number} {# greater than}
else {# not even in the ballpark}

I'd also do a
if {(![string is integer -strict $text]) || ($text < 0) || ($text > 50)} {
# tell the user the guess has to be a NUMBER between 1 and 50
}

Also, you do not provide any default/fallback error message, so of course it's just doing "return" and not saying anything cos it never matches because "1" is not the same as 1
{$text == "\"1\""}
would match IF the user typed
guess "1"

I'd put a default message in there after the else, at least something like
puthelp "PRIVMSG $nick :Nope, no number matched.."
return
Post Reply