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.

Database question?

Help for those learning Tcl or writing their own scripts.
Post Reply
N
Nara
Halfop
Posts: 40
Joined: Sun Jul 23, 2006 11:12 pm

Database question?

Post by Nara »

I currently use a text file that is named as a .dat to store my eggdrop's custom settings and variables, which is loaded and saved on each load. However, it wipes like weekly to bi-weekly. I think it may have something to do with the way I sync or it could be the file system. Yes, mIRC colour codes are stored within the file if that means anything.

Sync/Load code:

Code: Select all

proc sync {} {
        global head tail delim djlist datafile cmdlist website public_channel p$

        if { [file exists $datafile] } {

                set FD [open $datafile r]
                set djlist ""
                while { ![eof $FD] } {
                        gets $FD line
                        set index [string first ":" $line ]
                        set name [string range $line 0 [expr {$index - 1}]]
                        set value [string range $line [expr {$index + 1}] end ]

                        switch -exact $name {

                                "head" {
                                        set head $value
                                }
                              "tail" {
                                        set tail $value
                                }

                                "delim" {
                                        set delim $value
                                }

                                "dj" {
                                        lappend djlist $value
                                }

                                "cmdlist" {
                                        set cmdlist $value
                                }

                                "website" {
                                        set website $value
                                }

                                "public_channel" {
                                        set public_channel $value
                                }

                                "private_channel" {
                                        set private_channel $value
                                }

                                "shoutcast" {
                                        set shoutcast $value
                                }

                                "shoutport" {
                                        set shoutport $value
                                }
                                "shoutpass" {
                                        set shoutpass $value
                                }

                                "topicmask" {
                                        set topicmask $value
                                }

                                "stream" {
                                        set stream $value
                                }

                                "rules" {
                                        set rules $value
                                }

                                "autodj" {
                                        set autodj $value
                                }

                                "greet1" {
                                        set greet1 $value
                                }

                                "greet2" {
                                        set greet2 $value
                                }
                                "greet3" {
                                        set greet3 $value
                                }

                                "ads" {
                                        set ads $value
                                }

                                "friends" {
                                        set friends $value
                                }

                                "schedules" {
                                        set schedules $value
                                }

                        }
                }
                close $FD
        }
}

Flush/Save code:

Code: Select all

proc battle:flush {} {
        global head tail delim djlist datafile cmdlist website public_channel pr$
        set FD [open $datafile w]

        puts $FD "cmdlist:$cmdlist"
        puts $FD "head:$head"
        puts $FD "tail:$tail"
        puts $FD "delim:$delim"
        puts $FD "website:$website"
        puts $FD "topicmask:$topicmask"
        puts $FD "shoutcast:$shoutcast"
        puts $FD "shoutport:$shoutport"
        puts $FD "shoutpass:$shoutpass"
        puts $FD "public_channel:$public_channel"
        puts $FD "private_channel:$private_channel"
        puts $FD "stream:$stream"
        puts $FD "rules:$rules"
        puts $FD "autodj:$autodj"
        puts $FD "greet1:$greet1"
        puts $FD "greet2:$greet2"
        puts $FD "greet3:$greet3"
        puts $FD "ads:$ads"
        puts $FD "friends:$friends"
        puts $FD "schedules:$schedules"
        foreach dj $djlist {
                puts $FD "dj:$dj"
        }
        close $FD
}
Basically: I want to solve the problem of it wiping itself. I'm more convinced its the linux file system not liking the colour codes or something though, as both of my backup files got wiped too.
User avatar
Sir_Fz
Revered One
Posts: 3794
Joined: Sun Apr 27, 2003 3:10 pm
Location: Lebanon
Contact:

Post by Sir_Fz »

Why don't you save them in the form:
set var1 bla
set var2 blo
...
and simply source the file.
N
Nara
Halfop
Posts: 40
Joined: Sun Jul 23, 2006 11:12 pm

Post by Nara »

Because I never knew you could do that. So, just put them in a blank file, name it .tcl, and load it before the script in the eggdrop configuration?
User avatar
Sir_Fz
Revered One
Posts: 3794
Joined: Sun Apr 27, 2003 3:10 pm
Location: Lebanon
Contact:

Post by Sir_Fz »

Yes, or you can load it inside the script before the code starts (i.e. add source scripts/variables.tcl before starting the code).

PS: It doesn't have to be a .tcl file, that's just a standard.
m
metroid
Owner
Posts: 771
Joined: Wed Jun 16, 2004 2:46 am

Post by metroid »

source can load any file, it just won't react too well on non-tcl code.

you can give it any extension you want, or no extension at all.
Post Reply