problem with actor:HasObject() (partially solved)
I want to make sure that the command unit could not leave the map on the ship.
It was assumed that this script creates a copy of the commander under the ship and destroy the ship with the commander sitting inside.
For some reason the script does not work.
And it does not work because of the presence of these words: actor:HasObject("Brain Robot").
I discovered this after a few attempts.
I'm shocked.
What's funny, once this script to work correctly.
How to get this bastard to work?
Code:
--function 1
function Equanimity:Return()
for actor in MovableMan.Actors do
if (actor:IsInGroup("Craft")) and (actor:HasObject("Brain Robot")) and (actor.Pos.Y < -20) then
self.Brain2 = CreateAHuman("Brain Robot","Base.rte");
self.Brain2.Pos = actor.Pos + Vector(0, 30);
MovableMan:AddActor(self.Brain2);
self:SetPlayerBrain(self.Brain2, 0);
actor.ToDelete = true;
self:SwitchToActor(self.Brain2,Activity.PLAYER_1,Activity.TEAM_1);
self.MesRet = 1;
self.TimerRet:Reset();
end
end
if self.MesRet == 1 then
if (self.TimerRet:IsPastSimMS(0)) and not (self.TimerRet:IsPastSimMS(5000)) then
FrameMan:SetScreenText("Where are you going? The work is not finished yet.", 0, 0, 5000, false);
end
end
end
---
I rewrote the code in this way.
If the ship gets the "Robot 1" then the console displays only the numbers 2 and 4.
All other functions in the mission work.
Code:
--function 2
function Equanimity:Return2()
print('2');
for actor in MovableMan.Actors do
if (actor.ClassName == "ACraft") and (actor:HasObject("Robot 1")) then
print('3');
end
end
print('4');
end