How to load values from a .txt file?

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.
User avatar
Robin
The Omniscient
Posts: 6506
Joined: Fri Feb 20, 2009 4:29 pm
Location: The Netherlands
Contact:

Re: How to load values from a .txt file?

Post by Robin »

We might be able to help you if you make a .love out of your game and upload that.
Help us help you: attach a .love.
User avatar
s-ol
Party member
Posts: 1077
Joined: Mon Sep 15, 2014 7:41 pm
Location: Cologne, Germany
Contact:

Re: How to load values from a .txt file?

Post by s-ol »

louie999 wrote:
zorg wrote:Then you want that one line to look like this:

Code: Select all

for row in love.filesystem.lines("maps/map1.txt") do
Unfortunately I also tried that but it's the same result:

Code: Select all

main.lua:4: Could not open file maps/map1.txt. Does not exist.

Traceback

[C]: in function 'lines'
main.lua:4: in function 'load'
[C] in function 'xpcall'
:?
Obviously you either misspelled the filename or path or put the file or folder into the wrong directory.

s-ol.nu /blog  -  p.s-ol.be /st8.lua  -  g.s-ol.be /gtglg /curcur

Code: Select all

print( type(love) )
if false then
  baby:hurt(me)
end
louie999
Prole
Posts: 46
Joined: Fri Mar 06, 2015 9:01 am

Re: How to load values from a .txt file?

Post by louie999 »

Ok here's the .love file.
S0lll0s wrote:Obviously you either misspelled the filename or path or put the file or folder into the wrong directory.
I didn't misspelled it, I've checked it over 10 times and nothing is misspelled. The file path for the main.lua file is C:/Games/main.lua and the file path for the map1.txt is C:/Games/maps/map1.txt
Attachments
main.love
(359 Bytes) Downloaded 51 times

Code: Select all

fun = true
school = true

function isItFun()
    if school then
       fun = false
    end
    if not fun then 
       me:explode()
    end
end
User avatar
zorg
Party member
Posts: 3444
Joined: Thu Dec 13, 2012 2:55 pm
Location: Absurdistan, Hungary
Contact:

Re: How to load values from a .txt file?

Post by zorg »

That file's literally only the main.lua; nothing else is in that .love file.
We did mean your whole game, including the folder structure and the txt 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
I~=Spam
Party member
Posts: 206
Joined: Fri Dec 14, 2012 11:59 pm

Re: How to load values from a .txt file?

Post by I~=Spam »

Can you press open a command line and cd to the directory and run "dir" and post the output of dir? (To do that press start type "cmd" press enter. Type "cd C:\Games" + enter in the new window. Then type "dir".)
My Tox ID: 0F1FB9170B94694A90FBCF6C4DDBDB9F58A9E4CDD0B4267E50BF9CDD62A0F947E376C5482610
louie999
Prole
Posts: 46
Joined: Fri Mar 06, 2015 9:01 am

Re: How to load values from a .txt file?

Post by louie999 »

I~=Spam wrote:Can you press open a command line and cd to the directory and run "dir" and post the output of dir? (To do that press start type "cmd" press enter. Type "cd C:\Games" + enter in the new window. Then type "dir".)
I don't know if I did it correctly but:
Image
zorg wrote:That file's literally only the main.lua; nothing else is in that .love file.
We did mean your whole game, including the folder structure and the txt file.
C:
Image
Inside the "Games" folder:
Image
Inside the "maps" folder:
Image

Code: Select all

fun = true
school = true

function isItFun()
    if school then
       fun = false
    end
    if not fun then 
       me:explode()
    end
end
User avatar
Garmelon
Prole
Posts: 19
Joined: Tue Jun 02, 2015 5:25 pm

Re: How to load values from a .txt file?

Post by Garmelon »

When creating the .zip you have to make sure you add the other folders too.
Did you open the "Games" folder with löve when you tested your code?
I made a small example.love with images from the wiki.
Attachments
example.love
(7.52 KiB) Downloaded 52 times
louie999
Prole
Posts: 46
Joined: Fri Mar 06, 2015 9:01 am

Re: How to load values from a .txt file?

Post by louie999 »

Garmelon wrote:When creating the .zip you have to make sure you add the other folders too.
Did you open the "Games" folder with löve when you tested your code?
I made a small example.love with images from the wiki.
OH, now I get it. So I put the folders(with the files) in the .zip file then I changed it to a .love file then it opens up without any errors. Though I don't get it, the images didn't show up even though theres no errors :(

Code: Select all

fun = true
school = true

function isItFun()
    if school then
       fun = false
    end
    if not fun then 
       me:explode()
    end
end
User avatar
Garmelon
Prole
Posts: 19
Joined: Tue Jun 02, 2015 5:25 pm

Re: How to load values from a .txt file?

Post by Garmelon »

louie999 wrote:Though I don't get it, the images didn't show up even though theres no errors :(
In the main.lua you posted a few posts ago you didn't render the images. Also you didn't store the images you created using love.graphics.newImage() anywhere. I fixed that in my main.lua in my example.
louie999
Prole
Posts: 46
Joined: Fri Mar 06, 2015 9:01 am

Re: How to load values from a .txt file?

Post by louie999 »

Garmelon wrote: In the main.lua you posted a few posts ago you didn't render the images. Also you didn't store the images you created using love.graphics.newImage() anywhere. I fixed that in my main.lua in my example.
So when I store the love.graphics.newImage(), then I need to use love.graphics.draw() to make it visible? if yes then should I put it in the love.draw() ?
----EDIT------
Oh wait nevermind I got it to work :awesome:
Code:

Code: Select all

local tiles = {}

function love.load()
	for row in love.filesystem.lines("maps/map1.txt") do
	    local x, y, path = string.match(row, "(%d*),(%d*),\"(.*)\"")
		table.insert(tiles,{id = love.graphics.newImage(path), x = tonumber(x), y = tonumber(y), path = path})
	end
end

function love.draw()
    for _, imgs in pairs(tiles) do
		love.graphics.draw(imgs.id, imgs.x, imgs.y)
	end
end

Code: Select all

fun = true
school = true

function isItFun()
    if school then
       fun = false
    end
    if not fun then 
       me:explode()
    end
end
Post Reply

Who is online

Users browsing this forum: No registered users and 87 guests