PtokaX forum

Development Section => Your Developing Problems => Topic started by: nErBoS on 26 October, 2003, 17:20:23

Title: If File doesn?t exist...
Post by: nErBoS on 26 October, 2003, 17:20:23
Hi all,

I am trying to read a text file that was creating by other commands but i want to make a "if" when the file doesn?t exits to send a message.

For example

arg = GetARG()
local username = GetItemByName (arg)
text = "txt/"..arg..".txt"

if username == nil then
  if text == nil
    user:SendPM(Bot, "There is no info")
  else
    readfrom(text)
end
end

It is working good on the read file but when the file doesn?t exist is not sending the msg !!

Can anyone help me !!

Best regards, nErBoS



Title:
Post by: tezlo on 26 October, 2003, 18:24:13
you dont need to GetItemByName()
and you dont want to check if text == nil
because you just set it equal to "txt/"..arg..".txt" so its always a string
unless GetARG(whatever it does) returned nil and you got a concat error

it says in the manual that readfrom() returns nil on error so..
if not readfrom(text) then user:SendPM(Bot, "no info on "..arg)

but you might want to display the info or do whatever with it so..
local file = readfrom(text)
if not file then user:SendPM(Bot, "..
else user:SendPM(Bot, file) end

btw.. if not file is the same as if file == nil
have fun
Title:
Post by: nErBoS on 26 October, 2003, 18:31:50
Thanks for the explination and help !!

Best regrads, nErBoS