[SOLVED]noob here - Can't load image

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
RAFAEL HEBER
Prole
Posts: 13
Joined: Thu Jan 22, 2015 1:23 am

[SOLVED]noob here - Can't load image

Post 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....
Last edited by RAFAEL HEBER on Wed Dec 30, 2015 12:29 am, edited 1 time in total.
User avatar
Nixola
Inner party member
Posts: 1949
Joined: Tue Dec 06, 2011 7:11 pm
Location: Italy

Re: noob here - Can't load image

Post 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
lf = love.filesystem
ls = love.sound
la = love.audio
lp = love.physics
lt = love.thread
li = love.image
lg = love.graphics
User avatar
s-ol
Party member
Posts: 1077
Joined: Mon Sep 15, 2014 7:41 pm
Location: Cologne, Germany
Contact:

Re: noob here - Can't load image

Post 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)

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
User avatar
RAFAEL HEBER
Prole
Posts: 13
Joined: Thu Jan 22, 2015 1:23 am

Re: noob here - Can't load image

Post by RAFAEL HEBER »

Detail: I'm using Ubuntu...
ham.zip
That the name of the folder
(12.06 KiB) Downloaded 284 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?
User avatar
pgimeno
Party member
Posts: 3684
Joined: Sun Oct 18, 2015 2:58 pm

Re: noob here - Can't load image

Post 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.
User avatar
RAFAEL HEBER
Prole
Posts: 13
Joined: Thu Jan 22, 2015 1:23 am

Re: noob here - Can't load image

Post 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?
User avatar
pgimeno
Party member
Posts: 3684
Joined: Sun Oct 18, 2015 2:58 pm

Re: noob here - Can't load image

Post 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.
User avatar
RAFAEL HEBER
Prole
Posts: 13
Joined: Thu Jan 22, 2015 1:23 am

Re: noob here - Can't load image

Post 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.
Attachments
maq.zip
(1.87 KiB) Downloaded 135 times
bobbyjones
Party member
Posts: 730
Joined: Sat Apr 26, 2014 7:46 pm

Re: noob here - Can't load image

Post 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 .
User avatar
RAFAEL HEBER
Prole
Posts: 13
Joined: Thu Jan 22, 2015 1:23 am

Re: noob here - Can't load image

Post 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).
Post Reply

Who is online

Users browsing this forum: Ahrefs [Bot], Amazon [Bot], Bing [Bot], Majestic-12 [Bot] and 7 guests