Page 1 of 1

Accesing a file in a completely different area of the .love directory.

Posted: Sun Apr 23, 2017 9:34 pm
by TrustyGun
First things first: the order of my work folder.

Image

What I am trying to do is access default.png from entity.lua. However, for the life of me, I can not figure out how.

Here's my current code; which currently doesn't work. As you can see, I have attempted to solve the issue by using the .. operator for lua. However, it doesn't work.

Code: Select all

Entity = Object:extend()

function Entity:new(img,x,y,xspeed,yspeed)
	self.img = love.graphics.newImage('../../assets/sprites/default.png')
	self.x = 0
	self.y = 0
	self.xspeed = 0
	self.yspeed = 0
end

function Entity:update(dt)

end

function Entity:draw()
	love.graphics.draw(img,x,y)
end
Any help would be appreciated!

Re: Accesing a file in a completely different area of the .love directory.

Posted: Mon Apr 24, 2017 1:33 am
by alloyed
As far as love is concerned, the working directory is _always_ the top of the game folder (or the save folder, or whatever). This means that "assets/sprites/default.png" should work, no matter what file it's written in.

EDIT: or it would, but your screenshot suggests it should actually be "assets/default.png" :p

Re: Accesing a file in a completely different area of the .love directory.

Posted: Mon Apr 24, 2017 10:13 am
by TrustyGun
Thank you. It works now. Also I feel slightly dumb for not knowing that :P