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 

Variables

 
This forum is locked: you cannot post, reply to, or edit topics.   This topic is locked: you cannot edit posts or make replies.    egghelp.org community Forum Index -> Archive
View previous topic :: View next topic  
Author Message
Jag
Halfop


Joined: 19 Sep 2003
Posts: 90

PostPosted: Wed Oct 08, 2003 1:43 am    Post subject: Variables Reply with quote

why when i closing the eggdrop, and reopen it the eggdrop clears all the variables? Sad
Back to top
View user's profile Send private message
user
 


Joined: 18 Mar 2003
Posts: 1452
Location: Norway

PostPosted: Wed Oct 08, 2003 1:30 pm    Post subject: Reply with quote

Because saving them would make little sense in most cases. If you want a value stored you'll have to do it yourself Smile
_________________
Have you ever read "The Manual"?
Back to top
View user's profile Send private message
Jag
Halfop


Joined: 19 Sep 2003
Posts: 90

PostPosted: Wed Oct 08, 2003 1:50 pm    Post subject: Reply with quote

Sad
10x any way Razz
Back to top
View user's profile Send private message
caesar
Mint Rubber


Joined: 14 Oct 2001
Posts: 3741
Location: Mint Factory

PostPosted: Wed Oct 08, 2003 2:04 pm    Post subject: Reply with quote

Using arrays will save them in memory ONLY if you restart the eggdrop, not kill it. To save an varialbe you must save it to disk as user said.
_________________
Once the game is over, the king and the pawn go back in the same box.
Back to top
View user's profile Send private message
user
 


Joined: 18 Mar 2003
Posts: 1452
Location: Norway

PostPosted: Wed Oct 08, 2003 2:22 pm    Post subject: Reply with quote

caesar wrote:
Using arrays will save them in memory ONLY if you restart the eggdrop, not kill it.

A restart makes a fresh tcl interpreter (so everything is lost). I think you meant 'rehash' Smile
_________________
Have you ever read "The Manual"?
Back to top
View user's profile Send private message
GodOfSuicide
Master


Joined: 17 Jun 2002
Posts: 463
Location: Austria

PostPosted: Wed Oct 08, 2003 4:39 pm    Post subject: Reply with quote

to backup an array:
Code:

proc write_array {name file} {
  set fp [open $file w]
  puts $fp [uplevel 1 [list array get $name]]
  close $fp
}

to restore the backup:
Code:

proc read_array {name file} {
  set fp [open $file r]
  uplevel 1 [list array set $name [read -nonewline $fp]]
  close $fp
}


credits for this code go to ppslim, slenox and all the others in the "backup array" thread Razz
Back to top
View user's profile Send private message
user
 


Joined: 18 Mar 2003
Posts: 1452
Location: Norway

PostPosted: Wed Oct 08, 2003 7:33 pm    Post subject: Reply with quote

GodOfSuicide wrote:
credits for this code go to ppslim, slenox and all the others in the "backup array" thread Razz

An alternative way would be to write it to the file as tcl code creating the array and just 'source the.file' (making the loading a bit faster I imagine) Where's that thread btw?

Edit: here's some generic code for variable storage:
Code:
# usage: var2str <qualified name> ?output name? ?pretty array boolean?
# the pretty array option is to choose between 'array set' or multiple 'set's for arrays with one or more elements
proc var2str {var {name {}} {prettyArray 0}} {
   if {$name=={}} {set name $var}
   if {[set var [uplevel 1 [list namespace which -variable $var]]]==""} {
      error "No such variable \"$name\""
   }
   upvar 1 $var v
   if {[info exists v]} {
      if {[array exists v]} {
         if {$prettyArray&&[array size v]} {
            foreach {ele val} [array get v] {
               lappend out [list set ${name}($ele) $val]
            }
            join [lsort -dict $out] \n
         } {
            list array set $name [array get v]
         }
      } {
         list set $name $v
      }
   } {
      list variable $name
   }
}
# usage: storeVar <variable name> <file name> ?file access mode?
proc storeVar {var file {mode w}} {
   set f [open $file $mode]
   puts $f [var2str $var $var 1]
   close $f
}

_________________
Have you ever read "The Manual"?
Back to top
View user's profile Send private message
Jag
Halfop


Joined: 19 Sep 2003
Posts: 90

PostPosted: Thu Oct 09, 2003 1:40 am    Post subject: Reply with quote

10x a lot!!!! Razz
Back to top
View user's profile Send private message
GodOfSuicide
Master


Joined: 17 Jun 2002
Posts: 463
Location: Austria

PostPosted: Thu Oct 09, 2003 3:07 am    Post subject: Reply with quote

user wrote:
Where's that thread btw?

http://forum.egghelp.org/viewtopic.php?t=4569&highlight=writearray
Back to top
View user's profile Send private message
Display posts from previous:   
This forum is locked: you cannot post, reply to, or edit topics.   This topic is locked: you cannot edit posts or make replies.    egghelp.org community Forum Index -> Archive 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