File error help?

General discussion about LÖVE, Lua, game development, puns, and unicorns.
Post Reply
chimmihc
Prole
Posts: 13
Joined: Mon Oct 19, 2015 6:32 am

File error help?

Post by chimmihc »

Hello, I am new to love and simply trying to learn the API.

The error I am getting is saying the file does not exist, but I have done some checking and the file is there and the path is correct.

Code:

Code: Select all

math.randomseed(os.time()*3)
local print = require("output")
local code = require("encode")
local path = require("gameroot")

love.load = function()
	os.setlocale ("", "time")
	print(os.date("%c") .. "\n------------------------------\n")
	print(io.open(path .. "\\assets\\orange.png")) -- a simple check to make sure the path is correct, prints "file (0x07fef215c500)"
	print(pcall(function() return love.graphics.newImage(path .. "\\assets\\orange.png") end)) -- prints "false   Could not open file C:/Users/myaccountname/Documents\TestGame\assets\orange.png. Does not exist."
end

love.quit = function()
	print("\n------------------------------\n\n\n")
end
What I read on the wiki page said nothing about any special behavior with the path.

If it will help, this is the gameroot file source:

Code: Select all

local GameName = love.filesystem.getIdentity()
local FilePath = love.filesystem.getSourceBaseDirectory()
return FilePath .. "\\" .. GameName

And the project view looks like this:


Image
User avatar
Nixola
Inner party member
Posts: 1949
Joined: Tue Dec 06, 2011 7:11 pm
Location: Italy

Re: File error help?

Post by Nixola »

You don't need to provide the full path to any LÖVE function; the path they receive is relative to the project root. It should just be lg.newImage("assets/orange.png").
Welcome to LÖVE by the way! ^^
lf = love.filesystem
ls = love.sound
la = love.audio
lp = love.physics
lt = love.thread
li = love.image
lg = love.graphics
User avatar
bartbes
Sex machine
Posts: 4946
Joined: Fri Aug 29, 2008 10:35 am
Location: The Netherlands
Contact:

Re: File error help?

Post by bartbes »

Nixola wrote:You don't need to provide the full path to any LÖVE function
And, as you've seen, you can't.
chimmihc
Prole
Posts: 13
Joined: Mon Oct 19, 2015 6:32 am

Re: File error help?

Post by chimmihc »

Well that is good to know, many thanks.
Post Reply

Who is online

Users browsing this forum: Ahrefs [Bot], Bing [Bot] and 5 guests