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.

Global Vars [Help] {Solved}

Help for those learning Tcl or writing their own scripts.
Post Reply
B
Branden
Halfop
Posts: 61
Joined: Sat Aug 04, 2007 8:36 pm

Global Vars [Help] {Solved}

Post by Branden »

Hi there,


I'm having an issue with vars, one proc is making the var, and I want another proc to be able to read that var.


Code: Select all

bind pub m|m "!LockDown" LockDown
bind pub m|m "!UnLock" UnLock
bind pubm - "*CONNECT*" CONNECTLOCKDOWN




proc LockDown { nick host hand chan text } {
	global botnick LockDown
	set LockDown on
	putquick "MODE $botnick +s +cFs"
	foreach chan [channels] {
		putquick "MODE $chan +mNipCRS"
		putquick "MODE $chan +k LockDownModeInitiated"
		putquick "PRIVMSG $chan Network is going into lockdown mode, from this point until LockDown is removed, no one will be able to connect to this network."
	}
}


proc UnLock { nick host hand chan text } {
	global botnick LockDown
	set LockDown off
	putquick "MODE $botnick -s -cFs"
	foreach chan [channels] {
		putquick "MODE $chan -mNipCRS"
		putquick "MODE $chan -k LockDownModeInitiated"
		putquick "PRIVMSG $chan Network is off of LockDown, everything is back to normal."
	}
}


proc CONNECTLOCKDOWN { nick host hand chan text } { 
	global LockDown
	set User [lindex [split $text] 3] 
	if {$chan == "#4ct1v1ty" && $LockDown == "on"} { 
		putserv "GLINE [stripcodes bcruag $User] 5m :Network is in lockdown mode, this ban will expire in 5 minuets, please reconnect at that time"
	} else { 
		return 
	} 
}


I get this error:

[10/04/08][14:48:04] <NightCrawler> [11:41] Tcl error [CONNECT]: can't read "LockDown": no such variable
Last edited by Branden on Sat Oct 04, 2008 3:13 pm, edited 1 time in total.
n
nml375
Revered One
Posts: 2860
Joined: Fri Aug 04, 2006 2:09 pm

Post by nml375 »

This is because the variable isn't declared yet. The global command only links the variable name in the local namespace to the one in globalspace, or simply, "myvar" is translated to "::myvar". You still have to create ::myvar.

In your case, it is most likely due to neither LockDown or UnLock being called yet. Easy fix would be to instantiate the variable as the script loads:

Code: Select all

...
bind pubm - "*CONNECT*" CONNECTLOCKDOWN
set LockDown off
...
NML_375
B
Branden
Halfop
Posts: 61
Joined: Sat Aug 04, 2007 8:36 pm

Post by Branden »

I'm getting this error AFTER the fact that LockDown or UnLock has been called on.
n
nml375
Revered One
Posts: 2860
Joined: Fri Aug 04, 2006 2:09 pm

Post by nml375 »

Looking a bit further, it seems the error is not in CONNECTLOCKDOWN, but in a proc named CONNECT.
NML_375
Post Reply