[SOLVED]program runs perfectly in IDE but errors in .love

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
jalamaya
Prole
Posts: 21
Joined: Wed Jan 13, 2016 9:14 pm

[SOLVED]program runs perfectly in IDE but errors in .love

Post by jalamaya »

Code: Select all

function love.load()
	imageLoc = "/resources/images/img1.png"
	imgA=love.graphics.newImage(imageLoc)
end
function love.draw()
	love.graphics.draw(imgA,0,0)
end
it runs perfectly in ZeroBrane IDE but when i compress it to .love file, i get an error: Could not open file... Does not exist.
Incidentally, when i try:

Code: Select all

imageLoc="C://Users/User/Desktop/randomImg.png"
i also get an error not just in compressed .love file but also in IDE
Last edited by jalamaya on Wed Jan 27, 2016 3:40 am, edited 1 time in total.
User avatar
kikito
Inner party member
Posts: 3153
Joined: Sat Oct 03, 2009 5:22 pm
Location: Madrid, Spain
Contact:

Re: program runs perfectly in IDE but errors in .love

Post by kikito »

Windows doesn't care about uppercase and lowercase letters. So if you save something as PLAYER.PNG, and open it as "player.png" or "player.PNG" or "Player.png", it "works".

This is not the case for the rest of the systems. OSX, Linux, and, critically, ZIP files, don't do this "case conversion". That's why it "works on windows" but not anywhere else.

The solution is: make sure that your files and the path you use to load them are EXACTLY the same (my personal preference is always using lowercase for filenames and extensions).
When I write def I mean function.
jalamaya
Prole
Posts: 21
Joined: Wed Jan 13, 2016 9:14 pm

Re: program runs perfectly in IDE but errors in .love

Post by jalamaya »

kikito wrote:Windows doesn't care about uppercase and lowercase letters. So if you save something as PLAYER.PNG, and open it as "player.png" or "player.PNG" or "Player.png", it "works".

This is not the case for the rest of the systems. OSX, Linux, and, critically, ZIP files, don't do this "case conversion". That's why it "works on windows" but not anywhere else.

The solution is: make sure that your files and the path you use to load them are EXACTLY the same (my personal preference is always using lowercase for filenames and extensions).
thank you very much! it worked now.

but what if my target image location is outside my source folder like in my second problem. i think love or lua in general reads my string as:

sourceFolder..imageLocation

thats why it can't locate my image. what should i do about that?
User avatar
kikito
Inner party member
Posts: 3153
Joined: Sat Oct 03, 2009 5:22 pm
Location: Madrid, Spain
Contact:

Re: program runs perfectly in IDE but errors in .love

Post by kikito »

jalamaya wrote:but what if my target image location is outside my source folder like in my second problem.
LÖVE does not allow reading things outside of the folder where main.lua is (or outside of the .love file) for security reasons. The only exception is the "data" folder, which is different for each system (windows, linux, osx). You can read more about this in [wiki]love.filesystem[/wiki]
When I write def I mean function.
jalamaya
Prole
Posts: 21
Joined: Wed Jan 13, 2016 9:14 pm

Re: program runs perfectly in IDE but errors in .love

Post by jalamaya »

kikito wrote:
jalamaya wrote:but what if my target image location is outside my source folder like in my second problem.
LÖVE does not allow reading things outside of the folder where main.lua is (or outside of the .love file) for security reasons. The only exception is the "data" folder, which is different for each system (windows, linux, osx). You can read more about this in [wiki]love.filesystem[/wiki]
since love2d has no open file dialog lib. i used love.textinput so the user will input the location of his desired image. does that mean if his desired image is not in the "data" folder, love will not read the image? :cry: :cry:
User avatar
slime
Solid Snayke
Posts: 3166
Joined: Mon Aug 23, 2010 6:45 am
Location: Nova Scotia, Canada
Contact:

Re: program runs perfectly in IDE but errors in .love

Post by slime »

Users can drag-and-drop files and folders onto the game's window, and you can read them via [wiki]love.filedropped[/wiki] and [wiki]love.directorydropped[/wiki]. Other than that, love functions can't access paths outside of the game's source and save directories.
jalamaya
Prole
Posts: 21
Joined: Wed Jan 13, 2016 9:14 pm

Re: program runs perfectly in IDE but errors in .love

Post by jalamaya »

slime wrote:Users can drag-and-drop files and folders onto the game's window
wow! that's actually a cool way of importing files. ill look into that tomorrow.

thank you all guys!
Post Reply

Who is online

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