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.

Two scripts - last one put in config works

Help for those learning Tcl or writing their own scripts.
Post Reply
K
Kobra
Voice
Posts: 2
Joined: Sat Mar 17, 2007 10:58 am

Two scripts - last one put in config works

Post by Kobra »

I have just started using eggdrop and TCL. I have written two scripts, but only one of them works - the one that is put lower in config. But both scripts work just fine on it's own (without the second one).

Code: Select all

source /home/kobra/eggdrop/scripts/cs.tcl
source /home/kobra/eggdrop/scripts/start.tcl
I guess I didn't put something in the code... but what?

Here is start.tcl

Code: Select all

package require http

proc getPage { url } {
    set token [::http::geturl $url]
    set data [::http::data $token]
    ::http::cleanup $token
    return $data
}

bind time -|- {* * * * *} akt

proc akt { minute hour day month year } {
    set page [ getPage http://some.com/site ]
    set a 1
    foreach line [split $page "\n"] {
	if { $a == 1 } {
	    set bufor "PRIVMSG #channel :\00312\002\[LeD\]\002\0033 $line \0031-"
	    set a 2
	    } else {
	    set bufor "$bufor \00314$line"
	    set a 1
	    puthelp "$bufor"
	    }
	}
    }
cs.tcl

Code: Select all

package require http

proc getPage { url } {
    set token [::http::geturl $url]
    set data [::http::data $token]
    ::http::cleanup $token
    return $data
}

bind time -|- {* * * * *} akt

proc akt { minute hour day month year } {
	set players 0
	set maxplayers 0
    if { [expr "$minute % 5"]==0 } {  
        set page [ getPage http://some.com/site ]
		set a 1
        set b 1
		foreach line [split $page "\n"] {
			switch $a {
			1	{}
			2	{ set nazwa $line }
			3	{ set adres $line }
			4	{ set players $line }
			5	{ set maxplayers $line }
			6	{ set map $line }
			7	{ set freezetime $line }
			8	{ set buytime $line }
			9	{ set mp_roundtime $line }
			10	{ set proxies $line }
			11	{ set maxrate $line }
			default {
				switch $b {
				1 { lappend nick $line }
				2 { lappend czas $line }
				3 {
					lappend kills $line
					set b 0
					}
				}
				set b [expr "$b + 1"]
				}
			}
			set a [expr "$a + 1"]
	    }
	set bufor "PRIVMSG #channel :\00312\002\[LeDsplej\]\002\0033 $players/$maxplayers \0031"
	puthelp "$bufor"
    }
}
Should i use "return 0" at the end of proc's? What am I doing wrong?

[These scripts work fine on it's own!]
User avatar
rosc2112
Revered One
Posts: 1454
Joined: Sun Feb 19, 2006 8:36 pm
Location: Northeast Pennsylvania

Post by rosc2112 »

They both have the same proc names, so the last one to load clobbers the 1st one's procs... Rename them to unique names, or use the namespace command (which is slightly more complicated.) Global vars should also use unique names.
K
Kobra
Voice
Posts: 2
Joined: Sat Mar 17, 2007 10:58 am

Post by Kobra »

so... the effect in eggdrop is the same, as if I would put all my scripts in one file? This is normal or is it a bug? So... I can use procnames from other script without including?
Last edited by Kobra on Sat Mar 17, 2007 5:24 pm, edited 1 time in total.
n
nml375
Revered One
Posts: 2860
Joined: Fri Aug 04, 2006 2:09 pm

Post by nml375 »

Yes, eggdrop will load any and all scripts into the same namespace and interpreter as it uses tcl's native "source" command. This behaviour is intended, as using namespaces requires special considderations when scripting, and creating multiple interpreter environments would require quite some work and use more resources, while really not providing any major advantages.

Of course, as rosc suggested, you can setup and use namespaces freely on your own, just as you would in any other tcl-enabled application.
NML_375
User avatar
rosc2112
Revered One
Posts: 1454
Joined: Sun Feb 19, 2006 8:36 pm
Location: Northeast Pennsylvania

Post by rosc2112 »

Kobra wrote: I can use procnames from other script without including?
Yes.
Post Reply