filesystem.load not working?

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
User avatar
Blank
Prole
Posts: 2
Joined: Mon Sep 22, 2014 2:12 pm

filesystem.load not working?

Post by Blank »

Hi there. My name is Blank, and I recently found LÖVE and I really thought it looked neat and simple, seeing as I have no past experience with LUA at all, and have only coded in GML. I am currently following a tutorial on youtube for LÖVE and I came across this problem with the code. I swear I have written everything correctly thus far, and I don't understand why this is not working.

I have set up an entities file for all of my projects objects, and have them loaded into the game when needed. Like the tutorial, I made a box object, suitably calling it 'box.lua' and giving it some properties.

part of main.lua

Code: Select all

function love.load()
	require ('entities')
	love.graphics.setBackgroundColor( 198,241,255 ) -- Red / Green / Blue
	imagePlayer = love.graphics.newImage("sprites/mero1.png")
	imageTiles = love.graphics.newImage("tiles/testtiles.png")
	
	local boxEnt = ents.Create( "box", 128, 128)
end
As you can see, I have 'boxEnt' loading my object from my 'entities.lua' file.

part of entities.lua

Code: Select all

ents = {}
ents.objects = {}
ents.objpath = "objects."

local register = {}
local id = 0

function ents.Startup()
	register["box"] = love.filesystem.load( "objects.box.lua" )
end

function ents.Derive(name)
		return love.filesystem.load( ents.objpath .. name .. ".lua" ) ()
end
The game loads fine, but like the tutorial, I have set up the script to throw me an error message in the command window if it does not load, and upon loading the game it tells me "Error: Entity box does not exist!" even though it DOES exists.


I have checked my filenames, directory names and everything and I just can't seem to figure this out.
Attachments
testproj.love
(104.11 KiB) Downloaded 149 times
User avatar
bartbes
Sex machine
Posts: 4946
Joined: Fri Aug 29, 2008 10:35 am
Location: The Netherlands
Contact:

Re: filesystem.load not working?

Post by bartbes »

It seems you forgot to call the function returned by load when trying to load objects.box.lua, is that the problem?
User avatar
artofwork
Citizen
Posts: 91
Joined: Mon Sep 15, 2014 1:17 am
Location: East Coast USA

Re: filesystem.load not working?

Post by artofwork »

1st problem is you never call ents.Startup() in love.load

Code: Select all

function love.load()
	require ('entities')
	love.graphics.setBackgroundColor( 198,241,255 ) -- Red / Green / Blue
	imagePlayer = love.graphics.newImage("sprites/mero1.png")
	imageTiles = love.graphics.newImage("tiles/testtiles.png")
	ents.Startup()
	local boxEnt = ents.Create( "box", 128, 128)
end

2nd problem is you need to change this

Code: Select all

register["box"] = love.filesystem.load( "objects.box.lua" )
to this

Code: Select all

register["box"] = love.filesystem.load( "/objects/box.lua" )
Now you get an error which is a good thing because it tells you that the change you made found what you were looking to load

Code: Select all

entities:26: attempt to call an upvalue 'register' (a table value)
To fix that you need to change this

Code: Select all

local ent = register(name) ()
to this

Code: Select all

local ent = register[name] ()
Then you get a new error

Code: Select all

entities: 13: attempt to call a nil value
In order to fix that we look at 13 which is

Code: Select all

return love.filesystem.load( ents.objpath .. name .. ".lua" ) ()
so we leave 13 alone, but make changes to the thing assigned to ents.objpath

from this

Code: Select all

ents.objpath = "objects."
to this

Code: Select all

ents.objpath = "/objects/"
Now we get a new error

Code: Select all

/objects/box.lua: 19: attempt to perform aithmetic on local 'dt' (a nil value)
We look at 19 in box.lua and see

Code: Select all

self.y = self.y + 32*dt
The problem isn't in 19 of box.lua its on line 18 of main.lua


The reason we know the error is in on line 18 of main.lua is because of the code on box.lua line 18

Code: Select all

function ent:update(dt)
main.lua line 18

Code: Select all

	ents.update(dt)
So we change line 18 of main from this

Code: Select all

	ents.update(dt)
to this

Code: Select all

	ents:update(dt)

And there are no more errors, Good Luck!
Post Reply

Who is online

Users browsing this forum: Bing [Bot] and 12 guests