Scripts / [SOLVED] Check if a file exists with Lua

Author
Message
thatandplaygames
4
Years of Service
User Offline
Joined: 12th Feb 2020
Location: In a creative space
Posted: 26th Jul 2022 20:16 Edited at: 26th Jul 2022 21:21
Hello,
How would a script look like if I wanted an entity to check if a file exist and if true it destroys itself?

Here is what I have. The text file is there in the mapbank but I'm getting - Prompt("File NOT Found. ")

-- Check for file

function filecheck_init()
file = io.open("filetester.txt", "r")
if file ~= nil then
io.input(file)
io.close(file)
Prompt("File WAS Found. ")
Destroy(e) else
Prompt("File NOT Found. ")
Destroy(e)
end
end

The author of this post has marked a post as an answer.

Go to answer
thatandplaygames
4
Years of Service
User Offline
Joined: 12th Feb 2020
Location: In a creative space
Posted: 26th Jul 2022 21:25
I'm so silly! The text file needs moved or I can use file = io.open("mapbank\\filetester.txt", "r")

It's working... but the entity is not being destroyed.

-- Check for file

function filecheck_init()
file = io.open("filetester.txt", "r")
if file ~= nil then
io.input(file)
io.close(file)
Prompt("File WAS Found. ")
Destroy(e) else
Prompt("File NOT Found. ")
Destroy(e)
end
end
thatandplaygames
4
Years of Service
User Offline
Joined: 12th Feb 2020
Location: In a creative space
Posted: 26th Jul 2022 21:40
My script is on a dynamic object. Destroy(e) is not removing it/destroying it. Thanks if you can help.
AmenMoses
GameGuru Master
8
Years of Service
User Offline
Joined: 20th Feb 2016
Location: Portsmouth, England
Posted: 27th Jul 2022 16:40
Can you attach the actual script rather than cut'n'paste.
Been there, done that, got all the T-Shirts!
PM
thatandplaygames
4
Years of Service
User Offline
Joined: 12th Feb 2020
Location: In a creative space
Posted: 27th Jul 2022 17:04
Yes, sorry and thank you. It's attached.

Attachments

Login to view attachments
AmenMoses
GameGuru Master
8
Years of Service
User Offline
Joined: 20th Feb 2016
Location: Portsmouth, England
Posted: 27th Jul 2022 20:05
This post has been marked by the post author as the answer.
Should be more like:
Been there, done that, got all the T-Shirts!

Attachments

Login to view attachments
PM
thatandplaygames
4
Years of Service
User Offline
Joined: 12th Feb 2020
Location: In a creative space
Posted: 27th Jul 2022 21:36
Thank you so very much!!

Login to post a reply

Server time is: 2024-04-25 02:34:51
Your offset time is: 2024-04-25 02:34:51