"Deleting" variables
Foreword: I have already submitted an issue on the Github repo here, before realizing that there was a forum and Discord server... OOPS!
Hello! I am writing small bits of code in attempt to break this engine, or find some faults. So far, it is a very good engine! The one major thing that I found as an issue - if I am trying to make some OOP-based game, I would want to delete some objects, more specifically, instances of a class. I have tried to do this by setting "this" to 0 when I want to delete an object, and checking if the object exists whenever trying to access it elsewhere. It's hard to explain, so here's an example.
Enemy = class
hp = 10
update = function() end
hit = function(damage)
hp -= damage
print("Ouch! I am "+hp)
if hp <= 0 then
print("Argh! I am dead now!")
this = 0
end
end
end
Player = class
constructor = function(opponent)
this.opponent = opponent
end
atkPts = 5
update = function()
if keyboard.press.SPACE then atk(opponent) end
end
atk = function(other)
if other then
other.hit(atkPts)
else
print("Miss!")
end
end
end
init = function()
enemy = new Enemy()
player = new Player(enemy)
end
update = function()
player.update()
enemy.update()
end
Here I am attacking an enemy on space pressed, and it does work. Console outputs when the enemy takes damage, and when the health is zero, it will print it's dead, but on further attacks, the enemy's health will still go into the negatives, never really dying. Please tell me if it's an issue with my code, or otherwise!