How to load values from a .txt file?
Forum rules
Before you make a thread asking for help, read this.
Before you make a thread asking for help, read this.
- 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?
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.
Re: How to load values from a .txt file?
Obviously you either misspelled the filename or path or put the file or folder into the wrong directory.louie999 wrote:Unfortunately I also tried that but it's the same result: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
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'
Re: How to load values from a .txt file?
Ok here's the .love file.
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.txtS0lll0s wrote:Obviously you either misspelled the filename or path or put the file or folder into the wrong directory.
- 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
- 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?
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.
We did mean your whole game, including the folder structure and the txt file.
Me and my stuff True 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.
Re: How to load values from a .txt file?
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
Re: How to load values from a .txt file?
I don't know if I did it correctly but: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".)
C: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.
Inside the "Games" folder:
Inside the "maps" folder:
Code: Select all
fun = true
school = true
function isItFun()
if school then
fun = false
end
if not fun then
me:explode()
end
end
Re: How to load values from a .txt file?
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.
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
Re: How to load values from a .txt file?
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 errorsGarmelon 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.
Code: Select all
fun = true
school = true
function isItFun()
if school then
fun = false
end
if not fun then
me:explode()
end
end
Re: How to load values from a .txt file?
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 wrote:Though I don't get it, the images didn't show up even though theres no errors
Re: How to load values from a .txt file?
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() ?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.
----EDIT------
Oh wait nevermind I got it to work
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
Who is online
Users browsing this forum: No registered users and 87 guests