i have a error in the chapter 14
Rusbelito opened this issue · comments
hi sheep hi masterr :3
I have a problem when following the guide n 14 I followed everything well until the moment when I had to try to restart the game, I mean create my conditional to detect if my bullet left the screen and load my love.load ()
I get an error related to classic.lua, I don't know how to solve it, I don't speak English and I use the translator haha I hope you can understand me <3
I will attach my project, I will appreciate any kind of help <3
Hello @Rusbelito,
The problem is the naming that you are using in the code. Please have a look at your main.lua
file.
function love.load()
Objecto = require "classic"
require "Jugador"
require "Enemigo"
require "Bala"
Jugador = Jugador() -- oops, Jugador is no longer an extended Object :(
Enemigo = Enemigo() -- oops, same goes here :(
ListaDeBalas = {}
end
function love.update(dt)
Jugador:update(dt)
Enemigo:update(dt)
for i,v in ipairs(ListaDeBalas) do
v:update(dt)
v:collicionR_R(Enemigo)
if v.dead then
table.remove(ListaDeBalas,i)
end
end
end
function love.draw()
Jugador:draw()
Enemigo:draw()
for i,v in ipairs(ListaDeBalas) do
v:draw()
end
end
function love.keypressed(key)
Jugador:keypressed(key)
end
What happens is that you are overwriting Jugador
and Enemigo
classes with their instances, so you no longer have a blueprint/instruction how to create a player or enemy anymore. When the game starts, it tries to create new
Player, but it won't be possible, since it's not a class that can be instantiated. Have a look at the fix:
function love.load()
Objecto = require "classic"
require "Jugador"
require "Enemigo"
require "Bala"
jugador = Jugador() -- now the blueprint stays intact :)
enemigo = Enemigo() -- enemy is also safe :)
ListaDeBalas = {}
end
function love.update(dt)
jugador:update(dt) -- we are updating a player instance here, not Player class anymore
enemigo:update(dt) -- same goes for the enemy
for i,v in ipairs(ListaDeBalas) do
v:update(dt)
v:collicionR_R(enemigo) -- let's trigger collision for the `enemy`, which is an instance of `Enemy` class
if v.dead then
table.remove(ListaDeBalas,i)
end
end
end
function love.draw()
jugador:draw()
enemigo:draw()
for i,v in ipairs(ListaDeBalas) do
v:draw()
end
end
function love.keypressed(key)
jugador:keypressed(key)
end
So, right now you are updating the instances, not that classes that serve as your blueprints/recipes.
I hope that helps :)