\\ is a windows thing you may want to use / instead to ensure your script works across platforms.
./ would allow you to use paths relative to the current working directory.
"rb" means that you are reading a binary file. with "txt" files you can just use "r"
Other than that the code looks fine.
ivan wrote: ↑Sun Sep 06, 2020 4:24 pm
\\ is a windows thing you may want to use / instead to ensure your script works across platforms.
./ would allow you to use paths relative to the current working directory.
"rb" means that you are reading a binary file. with "txt" files you can just use "r"
Other than that the code looks fine.
I still get "No such file or directory" when using / instead of \\.
Is this the correct way to use the relative path to the current working directory?
Maybe it's a permissions thing - Windows blocks certain directories if your account is not an administrator. That's why it's better to use love.filesystem - it's guaranteed to work across platforms.
The following works fine for me:
ivan wrote: ↑Sun Sep 06, 2020 4:56 pm
Maybe it's a permissions thing - Windows blocks certain directories if your account is not an administrator. That's why it's better to use love.filesystem - it's guaranteed to work across platforms.
The following works fine for me:
function readAll(filepath)
for line in love.filesystem.lines(filepath) do
local str = ""
str = str + line
end
return str
end
text = readAll('./data.txt')
I placed my text file also in the working directory:
love.filesystem does not allow access outside of the AppData directory and your game folder.
That's why love.filesystem is "safer" to use than the default io. module.
Windows won't allow you to mess with the C:/Program Files/ folder unless you are an administrator.
1. Using "./" means relative path, which relative to current working directory (usually where love.exe reside)
2. You shouldn't mix Lua "io" and LOVE "love.filesystem". Use Lua "io" if you want to open file anywhere (which leads to portability issue) and use LOVE "love.filesystem" if you want access files in your game.
Profile. Do you encounter crashes in LÖVE Android and wanna send me logcats? Please hit me up in LÖVE Discord and send the full logcat file!
AuahDark wrote: ↑Mon Sep 07, 2020 4:19 am
The short is:
1. Using "./" means relative path, which relative to current working directory (usually where love.exe reside)
2. You shouldn't mix Lua "io" and LOVE "love.filesystem". Use Lua "io" if you want to open file anywhere (which leads to portability issue) and use LOVE "love.filesystem" if you want access files in your game.
It always shows me "Could not open file.... Does not exist."
I placed my text file in the current working directory^^ I have added u on discord Can you help me please? I can start a screen transfer