PtokaX forum

Archive => Archived 4.0 boards => Request for Lua 4 scripts => Topic started by: Mondy on 19 January, 2004, 16:10:45

Title: Deleting text in a .txt file
Post by: Mondy on 19 January, 2004, 16:10:45
What i need to do is delete all the text that is in the text file.  Or delete the text file itself.

I have been looking around these forums for the last hour or so trying to learn how to use the write command to do this (im not even sure if that command can do this).  I have had no success and any help would be appriciated.

Thankyou
Title:
Post by: plop on 19 January, 2004, 16:19:55
remove(filename)
that deletes the given file.
if you want 2 make it empty just start writing 2 it, if you don't say it has 2 append it overwrites everything.

plop
Title:
Post by: Mondy on 19 January, 2004, 16:46:22
Well i cant even work out simple instrutions it seems.

This is what i have.
-----------------------------------
file = "text.txt"

function Main()
SetTimer(1000)
StartTimer()
end


function OnTimer()
readfrom(file)
while 1 do
local line = read()
if (line == nil) then
break
else
say = (line)
end
end

SendToAll(say)
remove(text.txt)

end
--------------------------------------

i am getting this error
Syntax Error: attempt to index global `text' (a string value)
Title:
Post by: pHaTTy on 19 January, 2004, 17:10:03
hmm

remove(text.txt)   <<<

remove("text.txt")

OR

filename = "text.txt"
remove(filename)

l8rr
Title:
Post by: Mondy on 19 January, 2004, 18:07:02
I just found the writeto(file) command before i only knew of the write().  That solved my problem.  I couldnt get the remove command to work.  Thanks for all the help i got anyway.

Heres the final script just incase anyone else needs this sort of thing.

file = "text.txt"

function Main()
SetTimer(1000)
StartTimer()
end


function OnTimer()
say = nil
readfrom(file)
while 1 do
local line = read()
if (line == nil) then
break
else
say = (line)
end
end
read()
SendToAll(say)
writeto(file)
end
Title:
Post by: Mondy on 20 January, 2004, 04:12:01
Well since i started using this thread for this script i might as well keep using it.  What iv been trying to create is a way for people to talk between an IRC channel and the Direct Connect channel.  Its working up to the point where in the direct connect channel whats being said is being echoed  e.g.

[14:07] not on ure side
[14:07] [IRC] > * not on ure side

What im trying to do now is get the script to parse out any lines that begin with "[IRC] > *"  The script that im using is included below and any help would be appreciated once again.  Thank you

file = "#irc.log"

function Main()
SetTimer(1000)
StartTimer()
end


function OnTimer()
say = nil
readfrom(file)
while 1 do
local line = read()
say = (line)

if (line == nil) then
  break
elseif (say == "[IRC] > * <") then
  break
else
  read()
  SendToAll(say)
  writeto(file)
end
Title:
Post by: plop on 20 January, 2004, 14:21:13
i got the idea that this is what you need.
prefix = { ["+"]=1,["!"]=1} --- insert all your command prefixes here
fileirc = "#irc.log"  ----- file from irc 2 be shown in dc
filedc = "dc.log"   ---- file from dc 2 be show in irc

function Main()
   SetTimer(1000)
   StartTimer()
end


function OnTimer()
   readfrom(fileirc)
   while 1 do
      local line = read()
      if (line == nil) then
         break
      else
         SendToAll(line)
      end
   end
   readfrom()
   remove(fileirc)
end

function DataArrival(user,data)
   if( strsub(data, 1, 1) == "<" ) then
      local tmp = strsub(data,1,1)
      if prefix[tmp]== nil then
         data=strsub(data,1,strlen(data)-1)
         appendto(filedc)
         write("[DC] "..data)
         writeto()
      end
   end
end
as you can see it uses 2 files.
1) stuff from irc 2 be shown on dc.
2) stuff from dc 2 be shown on irc (commands are filtered).

plop
Title:
Post by: Mondy on 20 January, 2004, 15:37:03
Thanks again its working now
Title:
Post by: plop on 20 January, 2004, 22:34:15
QuoteOriginally posted by Mondy
Thanks again its working now
yw.

can you post the irc part of this here so other ppl can use it 2 if they want ???
thx in adv.

plop
Title:
Post by: Mondy on 23 January, 2004, 14:41:47
Here are the Irc scripts.  [IRC] is used as a trigger to be parsed out.  

Theres this one.
/dc { if ( [IRC] isin $read("c:\path\to\log.log"))   /write -c ("c:\path\to\log.log")
  elseif (1 <= $lines(c:\path\to\log.log)) //msg #animesharensw $read("c:\path\to\log.log",$lines(c:\path\to\log.log))
  /write -c ("c:\path\to\log.log")
}

And this one

/dc {
  var %log = "c:\path\to\log.log"
  var %line = $read(%log, 1)
  while ($lines(%log) > 0) {
    if ($left(%line,7) != * [IRC]) /msg #animesharensw %line
    /write -dl1 %log
    %line = $read(%log, 1)
  }
}