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.
Old posts that have not been replied to for several years.
Dedan
Master
Posts: 260 Joined: Wed Jul 09, 2003 10:50 pm
Location: Memphis
Post
by Dedan » Sun Aug 24, 2003 9:05 am
Everytime i try to make a nice timed var, i run into this problem.
you can increase the value of a var with: "incr codes_flood 1"
why can't you decrease it in a "called" proc?
<stenone> [07:47] Tcl error in script for 'timer400':
<stenone> [07:47] expected integer but got "codes_flood"
Code: Select all
proc stuff {usual stuff} {
global stuff
if flood stuff
if {$codes_found >= $codes_max} {
incr codes_flood 1
utimer 7 [list flood:dec codes_flood]
}
proc flood:dec {var} {
global codes_flood
incr var -1
if {$var < "0"} {set var "0"}
return 0
}
Thanks for any help given
I once was an intelligent young man, now i am old and i can not remember who i was.
user
Posts: 1452 Joined: Tue Mar 18, 2003 9:58 pm
Location: Norway
Post
by user » Sun Aug 24, 2003 9:12 am
You pass the variable name to the proc and then try to incr the variable containing the variable name, which obviously won't work unless that name is a integer
I suggest using 'upvar' to import the variable...this way you can pass any variable name to the proc without risking screwups because the name is already taken.
Code: Select all
proc flood:dec {var} {
upvar 1 $var v
if {[incr v -1]<0} {set v 0}
}
caesar
Mint Rubber
Posts: 3778 Joined: Sun Oct 14, 2001 8:00 pm
Location: Mint Factory
Post
by caesar » Sun Aug 24, 2003 9:39 am
In the flood:dec proc don't forget to call globaly the var variable or use what user sugested.
Once the game is over, the king and the pawn go back in the same box.
Dedan
Master
Posts: 260 Joined: Wed Jul 09, 2003 10:50 pm
Location: Memphis
Post
by Dedan » Sun Aug 24, 2003 9:43 am
so, it should be:
Code: Select all
proc flood:dec {var} {
upvar 1 $var v
incr v -1
if {$v < 0} {set v 0}
}
I once was an intelligent young man, now i am old and i can not remember who i was.