I have a parasite I'm making. When it gets too close to other non-parasites, it infects them. They take damage every turn until they die and create a new parasite. I made a list of currently infected actors so that I wouldn't infect people multiple times. The problem was, if I didn't do that, people, because they got infected once every frame, died ridiculously fast and made a crabsplosion of parasites when they did. It's interesting, because if you infect one of the crabs at the crab level, the infection spreads across the map like a tidal wave and kills everything.
Anyways...
It works fine so far, however, I keep having problems getting rid of people from the array. I want to get rid of dead people because otherwise the array would get larger and larger, and if many people get infected, could use a lot of memory. I keep getting an error in DeleteSelf() (at the bottom) at line 48:
Code:
function Create(self)
--Find who to hurt by taking our mass, because we stored the actor ID in the mass when the particle was made.
self.victim = MovableMan:GetMOFromID(self.Mass);
--Determine the type of actor so we can access its info.
if self.victim.ClassName == "AHuman" then
self.victim = ToAHuman(self.victim);
elseif self.victim.ClassName == "ACrab" then
self.victim = ToACrab(self.victim);
else
--If it is neither quadroped nor biped, erase this as it is not the type of actor we can hurt.
DeleteSelf();
end
self.hurtInterval = 60;
--Timer to wait out intervals.
self.hurtTimer = Timer();
end
function Update(self)
if MovableMan:IsActor(self.victim) then
--If the actor's dead, gib it and spawn another parasite.
if self.victim.Health <= 0 then
local newParasite = CreateACrab("Parasite");
newParasite.Pos = self.victim.Pos;
self.victim:GibThis();
MovableMan:AddParticle(newParasite);
DeleteSelf();
else
--If the actor still exists and the timer is up, hurt it.
if self.hurtTimer:IsPastSimMS(self.hurtInterval) then
self.victim.Health = self.victim.Health - 1;
self.hurtTimer:Reset();
end
end
else
--If the actor is gone or dead, destroy this.
DeleteSelf();
end
end
function DeleteSelf()
for i, v in ipairs (infected) do
if v == self.victim then --LINE 48
table.remove(infected, i);
self.ToDelete = true;
end
end
end
It says I attempted to index the global "self", a nil value when the infected actor dies. Over and over. I don't understand what that means.