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.

Replacing line in file

Old posts that have not been replied to for several years.
Locked
z
zleppy
Voice
Posts: 13
Joined: Wed Apr 14, 2004 2:32 pm

Replacing line in file

Post by zleppy »

Hi i'm trying to make a higher/lower-game for a channel, and want to keep track of the scores...but i havent found out how to replace a line in a file...
i want to put the nick who guessed the corerct number in a file, or if it exists, just replace the line (and increase the number on it)..
got everything else covered...just this little part left...plz help ;)
-zleppy-
User avatar
caesar
Mint Rubber
Posts: 3778
Joined: Sun Oct 14, 2001 8:00 pm
Location: Mint Factory

Post by caesar »

Working with files had been discussed before a lot of times, even there is an example how to add, remove and replace an certain line from an text file, do an forum search. Also, I belive it will be a lot easier if you store the results in arrays and save them every 5 minutes or whatever to a file as backup. This also had been discussed before with examples and parts of code ofcource.
Once the game is over, the king and the pawn go back in the same box.
z
zleppy
Voice
Posts: 13
Joined: Wed Apr 14, 2004 2:32 pm

Post by zleppy »

thanks...i found a script that works...but now i have the problem that i cant figure out how to check if the array is existing...like...
a new user gets a point..ok... set $score($nick) 1
but what about a old user...how do i add 1 up to the existing value?
User avatar
caesar
Mint Rubber
Posts: 3778
Joined: Sun Oct 14, 2001 8:00 pm
Location: Mint Factory

Post by caesar »

dose your_array(thing) exists?

Code: Select all

if {![info exists your_array(thing)]} {
# do whatever
}
and increase it with "incr your_array(thing)"
Once the game is over, the king and the pawn go back in the same box.
z
zleppy
Voice
Posts: 13
Joined: Wed Apr 14, 2004 2:32 pm

Post by zleppy »

hmm...ok...almost done now...only one thing...
i found this proc:
proc save_hlowscores {nick host hand chan arg} {
global hlowscorearray scorefile hlowscore
set fp [open $scorefile w]
puts $fp [uplevel 1 [list array get $hlowscorearray]]
close $fp
return 0
}
or..have edited it some...
but how should i set a timer do do it?
i tried "timer 1 save_hlowscores", but that only crashed the bot...

-zleppy-
User avatar
caesar
Mint Rubber
Posts: 3778
Joined: Sun Oct 14, 2001 8:00 pm
Location: Mint Factory

Post by caesar »

it dies cos you haven't supplied all the arguments, so, use something like:

Code: Select all

proc save_hlowscores {} { 
global hlowscorearray scorefile hlowscore 
set fp [open $scorefile w] 
puts $fp [uplevel 1 [list array get $hlowscorearray]] 
close $fp 
return 0 
} 
and timer 1
    Once the game is over, the king and the pawn go back in the same box.
    Locked