After following Grif's advice and reviewing the statements, I came up with this much shorter and neater piece of code:
Code:
function Create(self)
-- The variables:
self.LilBusters = false;
end
function Update(self)
for actor in MovableMan.Actors do
local avgx = actor.Pos.X - self.Pos.X;
local avgy = actor.Pos.Y - self.Pos.Y;
local dist = math.sqrt(avgx ^ 2 + avgy ^ 2);
if not actor.IsActor then
if self.LilBusters == true then
self.LilBusters = false;
print ("LilBusters is OFF due to destruction");
end
end
-- if dist > 50 and self.LilBusters == true then
-- self.LilBusters = false;
-- print ("LilBusters is OFF due to distance");
-- end
if actor:IsInGroup("LowLegs") and dist < 50 then
if self:IsPlayerControlled() and self.LilBusters == false and UInputMan:KeyPressed(18) then
self.LilBusters = true;
print ("LilBusters is ON");
end
if self:IsPlayerControlled() and self.LilBusters == true and UInputMan:KeyPressed(20) then
self.LilBusters = false;
print ("LilBusters is OFF due to manual activation");
end
if self.LilBusters == true then
self.Pos.X = actor.Pos.X;
self.Pos.Y = actor.Pos.Y - 50;
end
end
end
end
Then I put the two actors close to each other, pressed the "R" key and, surprisingly enough, it worked. The actors attached to each other. There was one... minor problem, though. The attached actor's limbs started to slowly descend, like gooey jelly dripping out from a dark green ice cube. While I was puzzled trying to decipher where that disgusting comparison I made originated itself, the upper actor's arm touched the lower actor's head. On less time that it takes to wink an eye, both actors accelerated to velocities rarely seen by human eyes, immediately covering the surrounding terrain with their blood and mutilated guts.
As entertaining as that may be, it is not, by any means, what I intended them to do. Does someone know what is causing such effect? Any help is appreciated.
(By the way, I made some experiments, and discovered that the farther one actor is from the other, the longer they take to explode, and the faster their body parts fly.)