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
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
Thanks for the explination and help !!
Best regrads, nErBoS