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.

botscript doesn't save some variables

Old posts that have not been replied to for several years.
C
CosmicD
Op
Posts: 102
Joined: Sat Dec 11, 2004 3:46 pm

Post by CosmicD »

CosmicD wrote:wow,

when i created the file in the eggdrop root it started saving data :).. thats cool

now I actually hope it'll also load this data on startup,

i created a sepparate tcl for this procedure you gave me...

UPDATE:
ok now it saves and loads all, thanks for your patience and help, i just need to do something and that is, to unify the way you set the file and you load the userfile on that last line

so i have the script you provided in a sepparate tcl:

Code: Select all

# saving your "topicinfo" array to "your.file"
bind evnt - save yourSave
bind evnt - prerehash yourSave

proc yourSave args {
   global topicinfo

   set file "mybot.public"

   if {[info exists topicinfo]} {
      if {[file writable $file]} {
         saveArray topicinfo $file
         putlog "Saving extra variables..."
      } else {
         putlog "can't write $file"
      }
   } else {
      putlog "no array? :/"
   }
}

proc saveArray {array file {mode w}} {
   if {![file writable $file]} return
   upvar 1 $array Array
   set data [array get Array]
   set f [open $file $mode]
   puts $f $data
   close $f
}

proc loadArray {array file} {
   if {![file readable $file]} return
   upvar 1 $array Array
   array set Array {}
   set f [open $file]
   set data [read -nonewline $f]
   close $f
   array set Array $data
}

loadArray topicinfo mybot.public
Well, shouldnt that last file now be:

Code: Select all

loadArray topicinfo $file
as a sidenote, could i also change set file to set variablefile and then use $variablefile (or something like that) just to really make sure that i am not obstructing any other vars or so
User avatar
user
 
Posts: 1452
Joined: Tue Mar 18, 2003 9:58 pm
Location: Norway

Post by user »

the variable can be called what ever you like, but take the code from my previous post and replace the same old proc (those checks we did for debugging are not needed any more)

Code: Select all

set yourFileVar "some.file"
proc yourSave args { 
	global topicinfo
	saveArray topicinfo $::yourFileVar
} 
loadArray topicinfo $yourFileVar
btw: did you miss the edit button or something? (that self-quote) :P
Have you ever read "The Manual"?
C
CosmicD
Op
Posts: 102
Joined: Sat Dec 11, 2004 3:46 pm

Post by CosmicD »

ack,

seems I can't follow anymore now.

i've been trying to change those to my own vars but every time i try to load the bot it gives a tcl error about the last "loadarray" line that it can't read $mychosenvar because it isn't set or smething..

although i also renamed the set mychosenvar , and then the file it should be,

something isn't really working, (and i'd like the debugging to be included still because that way i can be rememberd to actually touch the file in the root dir of eggdrop, so now I have something like this:

Code: Select all

#
bind evnt - save PubVarSave
bind evnt - prerehash PubVarSave

proc PubVarSave args {
   global topicinfo

   set file "botname.public"

   if {[info exists topicinfo]} {
      if {[file writable $file]} {
         saveArray topicinfo $file
         putlog "Saving extra variables..."
      } else {
         putlog "can't write $file, did you touch it in eggdrop root ?"
      }
   } else {
      putlog "no array. Have you loaded commands.tcl ? :/"
   }
}

proc saveArray {array file {mode w}} {
   if {![file writable $file]} return
   upvar 1 $array Array
   set data [array get Array]
   set f [open $file $mode]
   puts $f $data
   close $f
}

proc loadArray {array file} {
   if {![file readable $file]} return
   upvar 1 $array Array
   array set Array {}
   set f [open $file]
   set data [read -nonewline $f]
   close $f
   array set Array $data
}
# edit filename the same as your "set" file above
loadArray topicinfo botname.public
Well this code works , but i have that problem with the changing of the $file variable ..

when i change it to something and i also change LoadArray topicinfo $chanvars or something , the bot gives an error ...
User avatar
user
 
Posts: 1452
Joined: Tue Mar 18, 2003 9:58 pm
Location: Norway

Post by user »

Code: Select all

set yourFileName "some.file"

proc saveArray {array file {mode w}} {
	upvar 1 $array Array
	set data [array get Array]
	set f [open $file $mode]
	puts $f $data
	close $f
}
proc loadArray {array file} {
	if {![file readable $file]} return
	upvar 1 $array Array
	array set Array {}
	set f [open $file]
	set data [read -nonewline $f]
	close $f
	array set Array $data
}
proc yourSave args { 
	global topicinfo
	saveArray topicinfo $::yourFileName;# notice those :'s
} 
loadArray topicinfo $yourFileName
Have you ever read "The Manual"?
C
CosmicD
Op
Posts: 102
Joined: Sat Dec 11, 2004 3:46 pm

Post by CosmicD »

thx alot,

going to put an addlog into that oo, for your credit because i'm going to package that with the commands.tcl that's spread for dutch users
Locked