PtokaX forum

Archive => Archived 4.0 boards => Help with Lua 4 scripts => Topic started by: Psycho_Chihuahua on 17 November, 2004, 17:33:21

Title: small fix needed
Post by: Psycho_Chihuahua on 17 November, 2004, 17:33:21
Can someone help me fix this to reade out certain files at certain times?

file1 = "txt/file1.txt"
file2 = "txt/file2.txt"
file3 = "txt/file3.txt"
file4 = "txt/file4.txt"

current = date("%H:%M")
iMin = 1000*60
tTime = {
--["timestring"] = "show this string"
["06:00"] = DoFile(file1),
["09:30"] = DoFile(file2)
["12:00"] = DoFile(file3)
["22:00"] = DoFile(file4)
}
function Main()
current = date("%H:%M")
if tTime[current] then
SendToAll( ("---" ..current .."---"), tTime[current] )
end
frmHub:RegBot("---" ..current .."---")
SetTimer(iMin)
StartTimer()
end
function OnTimer()
frmHub:UnregBot("---" ..current .."---")
current = date("%H:%M")
if tTime[current] then
SendToAll( ("---" ..current .."---"), tTime[current] )
end
frmHub:RegBot("---" ..current .."---")
end
function OnExit()
frmHub:UnregBot("---" ..current .."---")
end
Title:
Post by: nErBoS on 18 November, 2004, 02:57:36
Hi,

You have some syntax error, compare this to yours and check it...

file1 = "txt\file1.txt"
file2 = "txt\file2.txt"
file3 = "txt\file3.txt"
file4 = "txt\file4.txt"

current = date("%H:%M")
iMin = 1000*60
tTime = {
--["timestring"] = "show this string"
["06:00"] = dofile(file1),
["09:30"] = dofile(file2),
["12:00"] = dofile(file3),
["22:00"] = dofile(file4),
}
function Main()
current = date("%H:%M")
if tTime[current] then
SendToAll( ("---" ..current .."---"), tTime[current] )
end
frmHub:RegBot("---" ..current .."---")
SetTimer(iMin)
StartTimer()
end

function OnTimer()
frmHub:UnregBot("---" ..current .."---")
current = date("%H:%M")
if tTime[current] then
SendToAll( ("---" ..current .."---"), tTime[current] )
end
frmHub:RegBot("---" ..current .."---")
end
function OnExit()
frmHub:UnregBot("---" ..current .."---")
end

Best regards, nErBoS
Title:
Post by: charlie on 21 November, 2004, 15:56:37
Hi,

is there a mistake in this script?
I try it, but it don?t work at this position: ["09:30"] = dofile(file2),

Can someone help?
Title:
Post by: nErBoS on 21 November, 2004, 18:05:18
Hi,

What do you have in the file2 to be done ???

Best regards, nErBoS
Title:
Post by: charlie on 21 November, 2004, 20:18:54
Here the code I Change, but it don?t work.
At special time the script should read out from special txtfile.


Bot = "TxT-Reader"

file1 = "txt\file1.txt"
file2 = "txt\file2.txt"
file3 = "txt\file3.txt"
file4 = "txt\file4.txt"

current = date("%H:%M")
iMin = 1000*60
tTime = {
--["timestring"] = "show this string"
["06:00"] = readfile(file1),
["09:30"] = readfile(file2),
["12:00"] = readfile(file3),
["22:00"] = readfile(file4),
}
function Main()
current = date("%H:%M")
if tTime[current] then
SendToAll( ("---" ..current .."---"), tTime[current] )
end
frmHub:RegBot("---" ..current .."---")
SetTimer(iMin)
StartTimer()
end

function OnTimer()
frmHub:UnregBot("---" ..current .."---")
current = date("%H:%M")
if tTime[current] then
SendToAll( ("---" ..current .."---"), tTime[current] )

end
frmHub:RegBot("---" ..current .."---")
end
function OnExit()
frmHub:UnregBot("---" ..current .."---")
end

function readfile(file)
local handle = openfile(file, "r")
if (handle ~= nil) then
    local line = read(handle)
    while 1 do
          if line == nil then break
          else  
          text = line
          text = ReplaceChars(text, "|", "--")
          text = ReplaceChars(text, "<", " ")
          text = ReplaceChars(text, ">", "| ")
          SendToAll(Bot,text)
          end
    end
end
closefile(handle)
end

function ReplaceChars(string, old, new)
   string = gsub(string, old, new)
   return string
end

Title:
Post by: nErBoS on 21 November, 2004, 21:31:18
Hi,

I am trying to understand your script, you are reading what ??? Code or simple text to be showed ???

Best regards, nErBoS
Title:
Post by: charlie on 21 November, 2004, 21:35:29
simple text in all txt files