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.

file check

Old posts that have not been replied to for several years.
Locked
s
sparta
Voice
Posts: 15
Joined: Sun Feb 27, 2005 10:02 am

file check

Post by sparta »

if {![info exists filename]} {
do stuff
} else {
do other stuff
}

that code should look for a file called "filename", if it dosent exist it should do some stuff, but if it exist it should do something else.. how do i fix this error ? cos now it say the file dosent exist even when it does.. or did i missunderstand something about this command/switches?
User avatar
caesar
Mint Rubber
Posts: 3778
Joined: Sun Oct 14, 2001 8:00 pm
Location: Mint Factory

Post by caesar »

You probably mean file (manipulate file names and attributes) not info (return information about the state of the Tcl interpreter) :mrgreen:
Once the game is over, the king and the pawn go back in the same box.
s
sparta
Voice
Posts: 15
Joined: Sun Feb 27, 2005 10:02 am

Post by sparta »

I got that to work, but now i got another problem.. :?:

Code: Select all

proc list_bchannels {userfile-loaded} {
  global "bitchchannels" 
    set datafile bitchchannels
    if {![file exists bitchchannels]}  {
    set r [open bitchchannels a+] 
     puts $r "."
     putlog "File bitchchannels missing, created it."
    catch {open $datafile r} rf
    foreach {a b c} [split [read $rf] \n] {
    close $rf      
     set:sbch $datafile $datafile $a
     } else {   
    if {![catch {open $datafile r} rf]} {
    foreach {a b c} [split [read $rf] \n] {
    putlog "Added channels: $a."
    set:sbch $datafile $datafile $a
    }
    close $rf
    } else { 
    putlog "Couldn't open $datafile for reading."
   } 
  }  
 }   
}
it creat the file "bitchchannels", then it put a "." in it if it dosent exist, thats ok, the file cant be empty since the bot reading from it and sets a var from the file, but it dosent go on after } else { . it halts there, and if the file dosent exist, then it should create it then trigger set:sbch $datafile $datafile $a, if the file exist it should read from it, then trigger the command "set:sbch $datafile $datafile $a", what cosing it to halt ? i have +d in console, i also have been looking with .tcl set errorInfo , and i get no info about what cosing the problem, all i get is that the var it should set is missing, thats cos the command never get triggered.. how do i solve this ?
User avatar
caesar
Mint Rubber
Posts: 3778
Joined: Sun Oct 14, 2001 8:00 pm
Location: Mint Factory

Post by caesar »

Code: Select all

proc list_bchannels {userfile-loaded} { 
  global bitchchannels
  set datafile bitchchannels 
  if {![file exists $datafile]} { 
    set f [open $datafile w] 
    close $f
    putlog "File $datafile missing, created it." 
  }
  set rf [open $datafile r]
  set data [split [read $rf] \n]
  close $rf
  foreach {a b c} $data { 
    set:sbch $datafile $datafile $a 
  } 
}
this should do fine.
Once the game is over, the king and the pawn go back in the same box.
s
sparta
Voice
Posts: 15
Joined: Sun Feb 27, 2005 10:02 am

Post by sparta »

with some modification that worked just fine, thnx for the help.. :) have to read a bit so i know what does what it that code tho ;)
Locked