egghelp.org community Forum Index
[ egghelp.org home | forum home ]
egghelp.org community
Discussion of eggdrop bots, shell accounts and tcl scripts.
 
 FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

Two scripts - last one put in config works

 
Post new topic   Reply to topic    egghelp.org community Forum Index -> Scripting Help
View previous topic :: View next topic  
Author Message
Kobra
Voice


Joined: 17 Mar 2007
Posts: 2

PostPosted: Sat Mar 17, 2007 11:06 am    Post subject: Two scripts - last one put in config works Reply with quote

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:
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:
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:
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!]
Back to top
View user's profile Send private message
rosc2112
Revered One


Joined: 19 Feb 2006
Posts: 1454
Location: Northeast Pennsylvania

PostPosted: Sat Mar 17, 2007 12:46 pm    Post subject: Reply with quote

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.
Back to top
View user's profile Send private message
Kobra
Voice


Joined: 17 Mar 2007
Posts: 2

PostPosted: Sat Mar 17, 2007 5:02 pm    Post subject: Reply with quote

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
Back to top
View user's profile Send private message
nml375
Revered One


Joined: 04 Aug 2006
Posts: 2857

PostPosted: Sat Mar 17, 2007 5:14 pm    Post subject: Reply with quote

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, idling at #eggdrop@IrcNET
Back to top
View user's profile Send private message
rosc2112
Revered One


Joined: 19 Feb 2006
Posts: 1454
Location: Northeast Pennsylvania

PostPosted: Sat Mar 17, 2007 10:37 pm    Post subject: Reply with quote

Kobra wrote:
I can use procnames from other script without including?

Yes.
Back to top
View user's profile Send private message
Display posts from previous:   
Post new topic   Reply to topic    egghelp.org community Forum Index -> Scripting Help All times are GMT - 4 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Forum hosting provided by Reverse.net

Powered by phpBB © 2001, 2005 phpBB Group
subGreen style by ktauber