Page 1 of 1
[SOLVED]program runs perfectly in IDE but errors in .love
Posted: Sun Jan 24, 2016 12:19 pm
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
Re: program runs perfectly in IDE but errors in .love
Posted: Sun Jan 24, 2016 12:38 pm
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).
Re: program runs perfectly in IDE but errors in .love
Posted: Sun Jan 24, 2016 12:56 pm
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?
Re: program runs perfectly in IDE but errors in .love
Posted: Sun Jan 24, 2016 1:15 pm
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]
Re: program runs perfectly in IDE but errors in .love
Posted: Sun Jan 24, 2016 1:50 pm
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?
Re: program runs perfectly in IDE but errors in .love
Posted: Sun Jan 24, 2016 2:20 pm
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.
Re: program runs perfectly in IDE but errors in .love
Posted: Sun Jan 24, 2016 2:34 pm
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!