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.

write to file problem

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

write to file problem

Post by sparta »

this is what i have so far:

Code: Select all

proc chwr {text} {
 global bitchchannel bitchchannels  
 set data "$text"
 if {$bitchchannel != ""} {set r [open $bitchchannels a+]; puts $r "[strftime "%d %b %Y, %H:%M %z"]: $data"; close $r}   
 putlog "Added $text to Bitch channel list."
 return 0
}
I know it's not right, but im new to this, so point me in the right direction, and i call the proc from this code:

Code: Select all

proc set:sbch {nickc hand text} {
 global channels 
 set channels "$text"
 putlog "S-Bitch channel set to: $channels"
 chwr $channels
}
User avatar
awyeah
Revered One
Posts: 1580
Joined: Mon Apr 26, 2004 2:37 am
Location: Switzerland
Contact:

Post by awyeah »

What error do you get while executing the first code? Type .tcl set errorInfo in DCC to check if there is an error after you have run the script.

Also make sure you have created the file which has the variable name $bitchchannels and it is in the correct directory as you have mentioned.
·­awyeah·

==================================
Facebook: jawad@idsia.ch (Jay Dee)
PS: Guys, I don't accept script helps or requests personally anymore.
==================================
s
sparta
Voice
Posts: 15
Joined: Sun Feb 27, 2005 10:02 am

Post by sparta »

This is the error i get:

Tcl error [set:sbch]: can't read "bitchchannel": no such variable

but since the seccond "script" works ok, then the problem must be in the first one, chwr $channels <<-- thats the line i call the proc chwr with.. and if i remove that line, then the seccond script work just fine, it add the var as it should, and no problem..

I guess the best way is to combine the two scripts, but since i dont have a clue on how to do that i made them separate..
User avatar
awyeah
Revered One
Posts: 1580
Joined: Mon Apr 26, 2004 2:37 am
Location: Switzerland
Contact:

Post by awyeah »

You haven't declared a variable named bitchchannel and yet you are using it in your proc and making it global. First:

set bitchchannel "i.am.lame"

Then try it! :lol:

And if you combine them it would be something like this, but you already have an error in your previous one so better fix that, before going ahead:

Code: Select all

proc set:sbch {nick hand text} {
 global bitchchannel bitchchannels
  if {$bitchchannel != ""} {
   set r [open $bitchchannels a+]
   puts $r "[strftime "%d %b %Y, %H:%M %z"]: $text"
   close $r
   putlog "Added $text to Bitch channel list."
  }   
 return 0
}
·­awyeah·

==================================
Facebook: jawad@idsia.ch (Jay Dee)
PS: Guys, I don't accept script helps or requests personally anymore.
==================================
s
sparta
Voice
Posts: 15
Joined: Sun Feb 27, 2005 10:02 am

Post by sparta »

I tryed your code, same result..

[12:13] Tcl error [set:sbch]: can't read "bitchchannel": no such variable

------------- EDIT ---------------

OK, i solved the problem, now to next part.. when i set a new channel, then i want the old one to be replaced with the new value, any way to do this ? or do i have to erase the file, then write a new one?
User avatar
awyeah
Revered One
Posts: 1580
Joined: Mon Apr 26, 2004 2:37 am
Location: Switzerland
Contact:

Post by awyeah »

If you want to add a new channel, replace your variable which is set to the channel or the <text> after the !trigger with the channel name. I am not sure which one are you talking about.

I don't think you would need to erase your database file as it has got nothing todo with it, you are just replacing the script to work on another channel.
·­awyeah·

==================================
Facebook: jawad@idsia.ch (Jay Dee)
PS: Guys, I don't accept script helps or requests personally anymore.
==================================
s
sparta
Voice
Posts: 15
Joined: Sun Feb 27, 2005 10:02 am

Post by sparta »

I want to replace the channel thats in the file, then over write it with a new channel or channels.. now if i add 1 more channel it ends up like:

#channel1
#channel2

but i want it to be only 1 line.. so if i type: .bchan #channel1 #channel2

then it write down the channels to the file bitchchannels.. and that file looks like:

#channel1 #channel2

and thats right, now i type: .bchan #channel3 #channel4

then the file will look like:

#channel1 #channel2
#channel3 #channel4

so it just add a new line, how would i replace the existing line with the new one? it should look like:

#channel3 #channel4

hope you understand :)
User avatar
user
&nbsp;
Posts: 1452
Joined: Tue Mar 18, 2003 9:58 pm
Location: Norway

Post by user »

if you don't want to append, don't open the file in append mode. AND if you're not going to read from it, ditch that "+"
Have you ever read "The Manual"?
s
sparta
Voice
Posts: 15
Joined: Sun Feb 27, 2005 10:02 am

Post by sparta »

if i ask like this then, how do i remove a file ? i want all old data stored in the file gone befor i add a new line to it.. the fastest way would be "rm" i guess ? but i dont know the command for that true a TCL, the comman need to be sent to the shell.. since i know the name of the file, then all i need is "command for rm" file_name .
User avatar
^DooM^
Owner
Posts: 772
Joined: Tue Aug 26, 2003 5:40 pm
Location: IronForge
Contact:

Post by ^DooM^ »

Code: Select all

[open $filename "w"]
this will completely overwrite your file with the new information.
The lifecycle of a noob is complex. Fledgling noobs gestate inside biometric pods. Once a budding noob has matured thru gestation they climb out of their pod, sit down at a PC, ask a bunch of questions that are clearly in the FAQ, The Noob is born
Locked