ents.objpath doesnt work well

General discussion about LÖVE, Lua, game development, puns, and unicorns.
Post Reply
theapple0
Prole
Posts: 1
Joined: Tue Oct 14, 2014 2:10 pm

ents.objpath doesnt work well

Post by theapple0 »

Hi there :)
I got an error But I dont know what to do with this

Code: Select all

ents = {}
ents.objects = {}
ents.objpath = "entities/"
local register = {}
local id = 0

function ents.Startup()
	register["box"] = love.filesystem.load( ents.objpath "box" )

end

function ents.Derive(name)
	return love.filesystem.load( ents.Objpath .. name .. "lua" ) ()
end

function ents.Create(name, x, y)
	if not x then
		x = 0
	end

	if not y then
		y = 0
	end

	if register[name] then
		id = id + 1
		local ent = register[name] ()
		ent:load()
		ent:setPos(x, y)
		ent.id = id
		ents.objects[#ents.objects + 1] = ent
		return ents.objects[#ents.objects]
	else
		print("Error: Entity" .. name .. " does not exist!")
		return false;
	end
end

function ents:update(dt)
	for i, ent in pairs(ents.objects) do
		if ent.update then
			ent:update(dt)
		end
	end
end

function ents:draw()
	for i, ent in pairs(ents.objects) do
		if ent.draw then
			ent:draw()
		end
	end
end
and the engain what runs is

Code: Select all

function love.load()
	require("entities")
	ents.Startup()
	xCloud = 0
	imageCloud_1 = love.graphics.newImage("pictures/cloud_1.png")
	enemy_1 = love.graphics.newImage("pictures/enemy_1.png")
	enemy_2 = love.graphics.newImage("pictures/enemy_2.png")
	grassbackground_1 = love.graphics.newImage("pictures/background_1.png")

	local boxEnt = ents.Create( "box", 128, 128 )
end

function love.draw()
	local x = love.mouse.getX( )
	local y = love.mouse.getY( )

	love.graphics.setColor( 182, 239, 254, 255 )
	love.graphics.rectangle( "fill", 0, 0, 800, 300 )

	love.graphics.setColor( 254, 255, 255, 255 )
	love.graphics.draw( imageCloud_1, xCloud -256, 128, 0, 1, 1, 0, 0 )

	love.graphics.setColor(255, 255, 255, 255)
	love.graphics.draw(grassbackground_1, 0, 0, 0, 1, 1, 0, 0)

	ents:draw()
end

function love.update(dt)
	xCloud = xCloud + 32*dt
	if xCloud >= (800 + 256) then
		xCloud = 0
	end
	ents:update(dt)
end

function love.focus(bool)
end

function love.keypressed( key, unicode )
end

function love.keyreleased( key, unicode )
end

function love.mousepressed( x, y, button )
end

function love.mousreleased( x, y, button )
end

function love.quit()
end
and what it should run is

Code: Select all

local ent = ents.Derive("base")

function ent:load( x, y )
	self:setPos( x, y)
	self.w = 64
	self.h = 64
end

function ent:setSize( w, h )
	self.w = w
	self.h = h
end

function ent:getSize()
	return self.w, self.h;
end

function ent:update(dt)
	self.y = self.y + 32*dt
end

function ent:draw()
	local x, y = self:getPos()
	local w, h = self:getSize()

	love.graphics.setColor(0, 0, 0, 255)
	love.graphics.rectangle("fill", x, y, w, h )
end

return ent;
THANK YOU ALL FOR READInG AND AT LEAS TRYING TO HELP ME :D
User avatar
Robin
The Omniscient
Posts: 6506
Joined: Fri Feb 20, 2009 4:29 pm
Location: The Netherlands
Contact:

Re: ents.objpath doesnt work well

Post by Robin »

Please upload a .love. Right now we don't know what the error message says or where it comes from, which makes it harder for us to help you.
Help us help you: attach a .love.
Post Reply

Who is online

Users browsing this forum: No registered users and 6 guests