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.

load scripts

Old posts that have not been replied to for several years.
Locked
User avatar
K
Voice
Posts: 34
Joined: Wed Jan 28, 2004 7:31 pm
Location: Romania @sibiu
Contact:

load scripts

Post by K »

if i have in dir scr 10 scripts file and i whant to load all these files with one command in eggdrop.conf
not like:

Code: Select all

source scr/script1.tcl
source scr/script2.tcl
.
.
.
and so one i wonder if is psobile to make a script and you add the lines in the scripts and add only that script to eggdrop.conf

Code: Select all

source scr/alscripts.tcl
g
greenbear
Owner
Posts: 733
Joined: Mon Sep 24, 2001 8:00 pm
Location: Norway

Post by greenbear »

Just add this to the end of your config file, and it'll load any *.tcl script inside the 'src/' dir

Code: Select all

set scriptdir scr/
foreach script [glob $scriptdir\*.tcl] { 
 source $script
}
User avatar
awyeah
Revered One
Posts: 1580
Joined: Mon Apr 26, 2004 2:37 am
Location: Switzerland
Contact:

Post by awyeah »

Nice useful code, gb. Might come in handy for me as well. I have many files, but I put all into one, like 400kb, but when I modify my scripts (almost like daily or so) then I have to upload all the 400kb, so I've split them again into smaller pieces, heh. I'll try it out as well.
·­awyeah·

==================================
Facebook: jawad@idsia.ch (Jay Dee)
PS: Guys, I don't accept script helps or requests personally anymore.
==================================
User avatar
K
Voice
Posts: 34
Joined: Wed Jan 28, 2004 7:31 pm
Location: Romania @sibiu
Contact:

no or yes

Post by K »

yes but if the scripts have diferent names it don't work and if i whant to start the scripts in a order that funtion even not :)
g
greenbear
Owner
Posts: 733
Joined: Mon Sep 24, 2001 8:00 pm
Location: Norway

Post by greenbear »

It will load any tcl script in the dir specified.

if you want to load the scripts in a particular order, you can for example do

Code: Select all

set scriptdir scr/
foreach script [lsort -dictionary [glob $scriptdir\*.tcl]] {
 source $script
}
and it will load them in alphabetic order.
User avatar
awyeah
Revered One
Posts: 1580
Joined: Mon Apr 26, 2004 2:37 am
Location: Switzerland
Contact:

Post by awyeah »

All files will have different names. You can't have 2 files with the same names, case-letters and extensions. They would cease to exist.

As for the names, all your tcl files have *.tcl extensions, so what ever names they have, or which ever case letters, this foreach loop will execute and load them, no matter what names/cases letters they have. So all scripts in your /scripts dir with the exention .tcl will be loaded.

As for sorting them alphabetically with respect to increasing or decreasing first letter of file names, you can use lsort.

To my knowledge what I have learned a few days ago.
Lsort can be use in such a way.

If I am right, this should be it.
For increasing alphabetical sequence or decreasing alphabetical sequence.

Code: Select all

#Will sort and load the files from alphabetically increasing first letters of file names
#(A to Z)
[lsort -dictionary -increasing [glob $scriptdir\*.tcl]]

#Will sort and load the files from alphabetically decreasing first letters of file names
#(Z to A)
[lsort -dictionary -decreasing [glob $scriptdir\*.tcl]]
For more switches on lsort. See the tcl manual with reference to the lsort function.
·­awyeah·

==================================
Facebook: jawad@idsia.ch (Jay Dee)
PS: Guys, I don't accept script helps or requests personally anymore.
==================================
m
metroid
Owner
Posts: 771
Joined: Wed Jun 16, 2004 2:46 am

Post by metroid »

Here is an even better code, It loads all scripts and if there is an error, it will do it will skip the script and tell u in a putlog

"ERROR: the following error occured while evaluating ${script}: $error"

:)

Here it is

Code: Select all

foreach script [glob scripts/*] {
  if {(![file isdirectory $script]) && ([regexp {^(.+)\.tcl$} $script])} {
    catch {source $script} error
    if {$error != ""} {
      putlog "ERROR: the following error occured while evaluating ${script}: $error"
    }
  }
}
ps. put this at the end of the eggdrop.conf
All credits go to perplexa for this script :)
Locked