|
Post by trybane on Aug 26, 2019 12:10:01 GMT
Hello, I am working on trying to make my script better. Right now, I am trying to loop through a number of images, but there will be instances where those images don't exist.
What I am looking to do is exception handling in essence, but all of the methods I have found online are not working for some reason I am unaware of. An example of a solution I found that is not working is:
function file_exists(name)
local f=io.open(name,"r")
if f~=nil then io.close(f) return true else return false end
end However, even when the file exists, it returns false and I get the error message I setup "File Not Found". The code I'm using this in is:
if file_exists(GeneralImagePath .. "_GeneratedStageCounterSnapshot" .. _currentStage .. ".png") then
scriptExit("Found File")
else
scriptExit("No File Found")
end If someone could either explain why this isn't working so that I may get it working OR give me an alternative solution that I could attempt I would be grateful.
|
|
|
Post by Exilereven on Aug 26, 2019 20:27:38 GMT
A function I use for creating and checking map files for a bot.
function saveMap(map) if not mkdir(System.MAPS) then simpleDialog("", "Unable to create folder maps") end
local fPointer = io.open(MAPS ..MAP_NAME .. ".lua", "w+") local text = "return" text = text .. table_to_string(map) fPointer:write(text) io.close(fPointer) simpleDialog("", System.MAPS .. MAP_NAME .. ".lua Created") end
Works no problem here. Maybe change the "r" to "w+" see if that works
|
|