PtokaX forum

Archive => Archived 5.0 boards => Request for scripts => Topic started by: Khezex on 13 March, 2005, 20:51:01

Title: Just take a look... (lua 4.0 to 5.0)
Post by: Khezex on 13 March, 2005, 20:51:01
Hello one and all... i've been trieing since for 2 days now, to update my bot (it's about 3 mb worth of text >.< ) ...
umm got cut up when tried to change this:

Quotefunction loadfile (data)
     assert(readfrom(data))
                  dostring(read("*all"))
            readfrom()
     end

TO this:

Quotefunction loadfile (data)
  local iFile = io.readfrom(data)
     if iFile then
        dofile(data)
        iFile:close()
     end
  end

I am not even sure if it has been corectly converted (found the piece of transfer on the forum...) ... umm my head hurts like crap right now... I keep getting "attempt to call field `readfrom' (a nil value)"
... anybody have any ideas ?

P.S. it's a fact, my head is in pain... changed io.readfrom to io.input ... and it dosen't give an error anymore... gotta se if it works dough
Title:
Post by: jiten on 13 March, 2005, 21:24:44
Try this:

function loadfile(data)
local handle = io.open(data,"r")
if (handle ~= nil) then
                dofile(data)
handle:flush()
handle:close()
        end
end


Best regards,

jiten
Title:
Post by: [_XStaTiC_] on 13 March, 2005, 21:34:56
this works to


function loadfile(file)
 local iFile = loadfile(file)
 if iFile then
iFile()
     end
end

Title:
Post by: Khezex on 13 March, 2005, 21:48:52
Umm jiten, thanks worked like a charm :D... you rock :P


function dosave(curUser)
test = "UserTable = {\r\n"
for a,b in UserTable do
if b == 1 then
writeto(SAVE)
test = test.."[\""..a.."\"]=\""..b.."\","
end
test = test.."\r\n}"
write(test)
writeto()
end
end



What about this one? :P

P.S. Static... you have function x... with local iFile = x(file) .... i get a stack overflow problem cause of self calling withouth a break controller :) .... just thought i should point that out :D

P.S.S: umm actually scratch that last one... i fixed it myself =))

Wow, just realized i didn't need a topic bot.... =)) (after 20 minutes of trying to edit the bot :P )
Title:
Post by: [_XStaTiC_] on 13 March, 2005, 22:11:42
Try this, maybe it will work.... Not tested


function dosave(curUser)
local f = io.open(SAVE, "w+")
assert(SAVE)
f:write("UserTable = {\n")
         for a,b in UserTable do
                  if b == 1 then
         f:write("[\""..a.."\"]=\""..b.."\",\n")
         end
        end
        f:write("}")
        f:flush()
        f:close()
end

Title:
Post by: Khezex on 14 March, 2005, 10:57:58
Static thanks... i kinda did that one on my own :P
Umm can anybody help me with the "APPENDTO" function?...
i have smth like this
FILE="name.txt"
io.appendto(FILE)
But i keep getting a "attempt to call field `appendto' (a nil value)" error... i really don't get it o.o... what am i doing wrong ?

i changed the code....
io.open(NEWS,"a")
handle= io.write("something to write")
io.close()
NOW... i get an " attempt to use a closed file " error.... sigh
Title:
Post by: jiten on 14 March, 2005, 11:21:34
Try to use this and change the values according to the files u got:

function AppendToFile(filename)
local file = io.open(filename, "a+") -- "a+"
file:write("appending this text to file "..filename.."\r\n")
file:write("continuing appending / writing text to file\r\n")
file:close()
end