Page 1 of 2
[SOLVED]noob here - Can't load image
Posted: Tue Dec 22, 2015 2:03 am
by RAFAEL HEBER
Hello for all
Simple put, I can't load image
Code: Select all
function love.load()
hamster=love.graphics.newImage"hamster.png"
end
function love.draw()
love.graphics.draw(hamster,100,100)
end
And the result is:" main.lua:2: Could not open file hamster.png. Does not exist"
I put the file "hamster.png" in the same folder of main.lua, but....
Re: noob here - Can't load image
Posted: Tue Dec 22, 2015 6:21 am
by Nixola
Can you make a .zip file with the contents of the folder (effectively making a .love file, if you just rename it) and upload it here?
Also, make sure the name is exactly the same, some systems are case sensitive
Re: noob here - Can't load image
Posted: Tue Dec 22, 2015 7:27 am
by s-ol
Well, the file hamster.png doesn't exist. Either it's in the wrong directory, or you misnamed it. If you are on linux or Mac, check for case, if you are on windows make sure you didn't call the file hamster.png.png or something like that (go to properties and check there)
Re: noob here - Can't load image
Posted: Tue Dec 22, 2015 3:48 pm
by RAFAEL HEBER
Detail: I'm using Ubuntu...
- ham.zip
- That the name of the folder
- (12.06 KiB) Downloaded 286 times
That's strange, the name in the code("Hamster.png") is equal as the archive.
Ah, and I don't use a texteditor not so know, TEXTADEPT. Can this be disturbing?
Re: noob here - Can't load image
Posted: Tue Dec 22, 2015 5:21 pm
by pgimeno
I think you're misunderstanding how LÖVE works.
LÖVE command line requires either a directory path or a file path.
If it is a (zip) file, then it won't look in the directory: It will use everything contained in the file as if it was in a separate directory.
I suspect that your problem is that you're trying to run it as follows: love main.love
And then the problem is that main.love does not contain Hamster.png, and that's what it's complaining about.
You can run programs in the current directory without zipping them into a love file, by writing: love .
You can also zip them, but if you do, the directory or file that you specify must contain a main.lua in the top level (not in any subdirectory). You did this part right with main.love, but you didn't include the image into main.love.
It works for me when I cd to ham/ and run your program as: love . (that's the recommended way for developing)
It also works for me when I *don't* cd to ham/ and run your program from its parent directory as: love ham
It also works for me if I do: zip main.love Hamster.png main.lua ; love main.love (that's how you package your game for distribution - make a zip with every asset the game needs; they can be in subdirectories within the zip file, as long as main.lua is in the top level of the zip file).
Hope that helps.
Re: noob here - Can't load image
Posted: Tue Dec 22, 2015 9:40 pm
by RAFAEL HEBER
You can also zip them, but if you do, the directory or file that you specify must contain a main.lua in the top level (not in any subdirectory). You did this part right with main.love, but you didn't include the image into main.love.
It also works for me if I do: zip main.love Hamster.png main.lua ; love main.love (that's how you package your game for distribution - make a zip with every asset the game needs; they can be in subdirectories within the zip file, as long as main.lua is in the top level of the zip file).
Hummmm, so I did this, I compressed both main.love and Hamster.png, rename as ham.love and then it's work!!!
pgimeno: Do you agree with this or there's a way more correct?
Re: noob here - Can't load image
Posted: Tue Dec 22, 2015 9:54 pm
by pgimeno
RAFAEL HEBER wrote:pgimeno: Do you agree with this or there's a way more correct?
It's as correct as any other way. You just don't need to zip it if all you want to do is test. Zipping is only necessary when packaging.
I use 'love .' while developing and 'zip -r myfile.love .' for distributing the .love file.
Re: noob here - Can't load image
Posted: Mon Dec 28, 2015 11:17 pm
by RAFAEL HEBER
Pgimeno:
Yes, I tested using terminal with ram.love --
"{directory}/ love ham.love" and worked, but...
When I try with another file like "maq.love" the results is other, this time I not compressed the archive and type 'love maq.love" or "love main.lua" and the result is no game found.
What's wrong I'm doing now?
The zip of the folder 'maq' is here.
Re: noob here - Can't load image
Posted: Tue Dec 29, 2015 12:13 am
by bobbyjones
Make sure you zip up the contents of the folder. But an easier way to run the code is to cd into the folder and do love .
Re: noob here - Can't load image
Posted: Tue Dec 29, 2015 12:26 am
by RAFAEL HEBER
Yes and I did this(in terminal, go to the directory of the folder and type: love maq.love), but don’t run, there's something that I don’t see... but what? (and note: maq.love is not compressed, but ham.love was compressed and work in the terminal).