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.

variable not getting unset

Old posts that have not been replied to for several years.
Locked
User avatar
z_one
Master
Posts: 269
Joined: Mon Jan 14, 2002 8:00 pm
Location: Canada

variable not getting unset

Post by z_one »

Hi,

What's wrong with this code, why isn't the variable arrchnck($chan:$bjmask) being unset ?
It's always incremented .... it never gets unset 4 seconds later.
note: bigjointimer is declared as a global variable.

Code: Select all

  if {![info exists arrchnck($chan:$bjmask)]} { 
    set arrchnck($chan:$bjmask) 1
    set bigjointimer($chan) [utimer 4 { unset arrchnck($chan:$bjmask) }]
  } else {
    set arrchnck($chan:$bjmask) [expr $arrchnck($chan:$bjmask) + 1]
  }
p
ppslim
Revered One
Posts: 3914
Joined: Sun Sep 23, 2001 8:00 pm
Location: Liverpool, England

Post by ppslim »

Code: Select all

set bigjointimer($chan) [utimer 4 { unset arrchnck($chan:$bjmask) }]
Tcl doesn't evaluate code within curly braces unless you pass it to a command that evaluates it. It would need to do this on the spot to function with the variables.

Try using

Code: Select all

set bigjointimer($chan) [utimer 4 [list unset arrchnck($chan:$bjmask) ]]
So that the variables are evaluated on the spot correctly.
User avatar
caesar
Mint Rubber
Posts: 3777
Joined: Sun Oct 14, 2001 8:00 pm
Location: Mint Factory

Post by caesar »

that's an array, and unset it like this:

Code: Select all

array unset arrchnck $chan $bjmask
or something like this anyway, I think..
Once the game is over, the king and the pawn go back in the same box.
s
stammer
Voice
Posts: 31
Joined: Mon Mar 10, 2003 9:39 am
Location: Bulgaria

Post by stammer »

Is it nessesery to unset all variables used in a tcl procedure like in other program languages or where in execution procedure is leaved variables is all unset automatically?
p
ppslim
Revered One
Posts: 3914
Joined: Sun Sep 23, 2001 8:00 pm
Location: Liverpool, England

Post by ppslim »

A variable exist only while its parent function is active.

Global variables (global is treated like a procedure in Tcl, though one your return, it exits), exist while global is running.

Anything in a procedure is created when needed, and destroyed on exit of the procedure.

Though, obviously, if you create a variable in a procedure, that you have declared as global, the global environment becomes the parent. This means it is only destroyed on exiting global.

The exception to the above, is specificly killing a variable using unset.
User avatar
z_one
Master
Posts: 269
Joined: Mon Jan 14, 2002 8:00 pm
Location: Canada

Post by z_one »

Hi,

ppslim I tried:

Code: Select all

set bigjointimer($chan) [utimer 4 [list unset arrchnck($chan:$bjmask) ]]
but the variable is still not getting unset. As for caesar's point, I am not sure how to use that array unset method.
User avatar
Papillon
Owner
Posts: 724
Joined: Fri Feb 15, 2002 8:00 pm
Location: *.no

Post by Papillon »

Code: Select all

set bigjointimer($chan) [utimer 4 [list array unset arrchnck $chan:$bjmask ]]
Elen sila lúmenn' omentielvo
Locked