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.

problems with dice code

Old posts that have not been replied to for several years.
Locked
w
wizzard

problems with dice code

Post by wizzard »

im a starter with tcl and was working on a little dice game, but i just keep getting errors on this code... have been searching around for a couple of hours now and tried lots of things but i cant get it to work.... whenever i call the proc throw evrything goes well untill it calls the proc calctotals. then it gives me this errormessage over the partyline :

[maxxje] [16:17] Tcl error [throw]: syntax error in expression "(3"

can anyone help me figure this out? TIA

Code: Select all

proc throw {nick host chan args} {

    global dice1
    global dice2
    global total    

    set dice1 [expr [rand 6] + 1]
    set dice2 [expr [rand 6] + 1]    

    putserv "notice $nick : Dice 1 : $dice1"
    putserv "notice $nick : Dice 2 : $dice2"
    
    
    [calctotals]    
    putserv "notice $nick : Total score for this throw : $total"
    putserv "notice $nick : Required score : ***"
}

proc calctotals {args} {
    
    global dice1
    global dice2
    global total

    if ($dice1 == $dice2){
	set total $dice1
	append total 00
    }
    
    if ($dice1 > $dice2){
	set total $dice1
	append total $dice2
    }
    
    if ($dice2 > $dice1){
	set total $dice2
	append total $dice1
    }
}
User avatar
stdragon
Owner
Posts: 959
Joined: Sun Sep 23, 2001 8:00 pm
Contact:

Post by stdragon »

Two problems:

1. [calctotals] should just be calctotals. Use [ ] around it when you want to use the return value, like set blah [calctotals].

2. The if statement's condition should be in { }, not ( ).

And a suggestion: if I remember correctly, eggdrop's rand function really sucks. It's better to use tcl's, like this: set dice1 [expr int(rand() * 6) + 1]

Even better, I found, is to use eggdrop's md5 function to create your own random number generator. It creates a smooth distribution and avoids long runs of the same number.
Locked