A lua script that uses io.lines for reading a txt file does not work in löve

Questions about the LÖVE API, installing LÖVE and other support related questions go here.
Forum rules
Before you make a thread asking for help, read this.
Post Reply
User avatar
scissors61
Citizen
Posts: 76
Joined: Fri Jan 08, 2016 10:16 am

A lua script that uses io.lines for reading a txt file does not work in löve

Post by scissors61 »

I created a script that reads through the text of a txt file to create a table and to add some values to each entry, well it does not work when I try to use it with löve, it says that when doing io.lines the txt file does not exists. Is lua limited when used in löve?
Attachments
japanese.love
(3.01 MiB) Downloaded 121 times
User avatar
Beelz
Party member
Posts: 234
Joined: Thu Sep 24, 2015 1:05 pm
Location: New York, USA
Contact:

Re: A lua script that uses io.lines for reading a txt file does not work in löve

Post by Beelz »

Instead of using the Lua reading function, use 'love.filesystem.lines'. Also Love cannot read anything outside of the game directory without some finesse. There are ways to do it, but it's more like a workaround.

Code: Select all

if self:hasBeer() then self:drink()
else self:getBeer() end
GitHub -- Website
User avatar
scissors61
Citizen
Posts: 76
Joined: Fri Jan 08, 2016 10:16 am

Re: A lua script that uses io.lines for reading a txt file does not work in löve

Post by scissors61 »

It worked!, I thought that lua worked completely in löve, but in some aspects it is kind of like box2d, were it has its own way of implementing things, Thanks Beelz!
User avatar
pgimeno
Party member
Posts: 3551
Joined: Sun Oct 18, 2015 2:58 pm

Re: A lua script that uses io.lines for reading a txt file does not work in löve

Post by pgimeno »

It's still Lua (LuaJIT actually). Lua isn't able to directly read files stored in .zip's and so isn't LÖVE. In order to access the files stored in the .love file or in your game directory, LÖVE provides the pertinent love.filesystem functions. You can think of the love.filesystem functions as a workaround for these Lua limitations.

Your program works fine for me when unzipped and run from the same directory with 'love .'

Edit: This works:
(in the directory with your unpacked files):
love .
lua convertidor.lua

This doesn't:
(in a different directory):
love <path to your unpacked files>
lua <path to your unpacked files>/convertidor.lua
love <your .love file>
lua <your .love file>/convertidor.lua
User avatar
zorg
Party member
Posts: 3444
Joined: Thu Dec 13, 2012 2:55 pm
Location: Absurdistan, Hungary
Contact:

Re: A lua script that uses io.lines for reading a txt file does not work in löve

Post by zorg »

If i recall correctly, it also works if you have the game in a love, and you get the source base directory, that will be the directory that contains the love file.
Me and my stuff :3True Neutral Aspirant. Why, yes, i do indeed enjoy sarcastically correcting others when they make the most blatant of spelling mistakes. No bullying or trolling the innocent tho.
User avatar
scissors61
Citizen
Posts: 76
Joined: Fri Jan 08, 2016 10:16 am

Re: A lua script that uses io.lines for reading a txt file does not work in löve

Post by scissors61 »

It is not clear to me yet from what I read from you guys, but the io.line script might work but only if the file is outside of the compressed .love app? Anyway, the game is complete, or the simple app,it is for a study group, it would be nice if it could read a txt file outside the compressed .love file, well this is my second thing I create with löve, I upload it if anyone wants to see, or learn the causative form of the japanese language ( yay!), the first thing I created was a game called cars avoiding cars with irregular hitboxes.
Attachments
japanese.love
(3.11 MiB) Downloaded 96 times
Post Reply

Who is online

Users browsing this forum: Google [Bot] and 61 guests