i have a error that not undersand , i need help

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
rusbelito
Prole
Posts: 9
Joined: Fri Jun 19, 2020 5:40 am

i have a error that not undersand , i need help

Post by rusbelito »

I am practicing lua with love 2d, I created a little video game in which you have to shoot your enemy and when you manage to hit him he accelerates his speed, and you lose when you miss a shot, I used a library called classic.lua and it was fine until the moment I wanted to make my game restart "load love.load ()" when a bullet came out of the screen, but when I load my love.load () I get an error related to the class, I've been trying for days with the solution but I do not understand what I did wrong, I will attach the minigame in a rar in case someone can help me
ejemplo.zip
(592.29 KiB) Downloaded 128 times
grump
Party member
Posts: 947
Joined: Sat Jul 22, 2017 7:43 pm

Re: i have a error that not undersand , i need help

Post by grump »

Manually calling love.load to restart a game requires very careful programming to make it go smooth. You're even calling it from love.update(), which is a good way to make sure weird things will happen if you're not super careful.

It's not meant to used that way; love will call it once when the game starts, but it doesn't do anything special, it doesn't reset anything, and it's not even necessary. It's just a mostly useless convention and a source of confusion for beginners.

A quick and easy workaround for you is to call love.quit('restart') instead. That's a "real" reset of your game, including the window, which will briefly flicker.
rusbelito
Prole
Posts: 9
Joined: Fri Jun 19, 2020 5:40 am

Re: i have a error that not undersand , i need help

Post by rusbelito »

Hello, thank you very much for answering, I still have not known how to solve it, I put the love.quit () and I have the same result, I believe that the problem is not in the love.load () but is related to the classic library .lua because that reset does not work even by creating a button in the same main class, for example that when pressing "r" it restarts, but I always have the same error result, an error related to classic.lua, and also my update which is where I have my love or in any case with the button, look I was following this tutorial, https://sheepolution.com/learn/book/14h ... rn/book/14, I don't understand why He works for him and not me: c
User avatar
ReFreezed
Party member
Posts: 612
Joined: Sun Oct 25, 2015 11:32 pm
Location: Sweden
Contact:

Re: i have a error that not undersand , i need help

Post by ReFreezed »

There seem to be some confusion about classes and instances. In love.load() you have:

Code: Select all

Jugador = Jugador()
Enemigo = Enemigo()
Here you're replacing the global reference to the class Jugador with a reference to an instance of the class. You probably want to do this:

Code: Select all

jugador = Jugador()
enemigo = Enemigo()
And then use jugador instead of Jugador etc. in the rest of the code, like this:

Code: Select all

Jugador:update(dt) -- Replace this
jugador:update(dt) -- with this.
Tools: Hot Particles, LuaPreprocess, InputField, (more) Games: Momento Temporis
"If each mistake being made is a new one, then progress is being made."
rusbelito
Prole
Posts: 9
Joined: Fri Jun 19, 2020 5:40 am

Re: i have a error that not undersand , i need help

Post by rusbelito »

Hello, thanks for your help, you can solve it as you told me and I know that the name of my variable cannot have the same instance of <3, thank you very much for taking the time to review my code <3
Post Reply

Who is online

Users browsing this forum: Google [Bot] and 47 guests