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.

Can you Help?

Help for those learning Tcl or writing their own scripts.
Post Reply
p
pektek
Halfop
Posts: 55
Joined: Sat Jul 01, 2023 4:51 pm

Can you Help?

Post by pektek »

Can we make this tcl points system?
Can we give points for every correct answer?

namespace eval GuessNumber {

    bind pub - !randomnumber [namespace current]::StartGame
    bind pub - !guess [namespace current]::Guess

    proc StartGame {nick host hand chan text} {
        variable number
        set number [RandomNumber 1 50]
        puthelp "PRIVMSG $chan :\00307\002\037(\037\002\00304$nick has started The Number Guessing Game.\00307\037\002)"
        puthelp "PRIVMSG $chan :\00307\002\037(\037\002\00304The Number Range is From:\002 1 \002To:\002 50 \002\00307\037\002)"
        puthelp "PRIVMSG $chan :\00307\002\037(\037\002\00304To Guess What Number Type: !guess <number>\002\00307\037\002)"
    }

    proc Guess {nick uhost hand chan text} {
        namespace upvar [namespace current] number no
        if {[scan $text {%d} value] != 1} {
            puthelp "PRIVMSG $chan :Sorry, that's not a valid number."
            return
        }

        CheckNumber $chan $nick $value
    }

    proc RandomNumber {min max} {
        return [expr {int(rand() * ($max - $min + 1)) + $min}]
    }

    proc CheckNumber {chan nick value} {
        variable number
        if {![info exists number] } {
            puthelp "PRIVMSG $chan :Sorry, there's nothing to guess cos game hasn't been started yet."
            return
        }
        if {$value == $number} {
            puthelp "PRIVMSG $chan :Congragulations, $nick, You Have Won!"
            unset number
        } elseif {$value > $number} {
            puthelp "PRIVMSG $chan :This Is Bigger than the correct Number"
        } else {
            puthelp "PRIVMSG $chan :This is Smaller than the correct Number"
        }
    }
}
thank you everyone in advence :wink:
Post Reply