Data Realms Fan Forums
http://45.55.195.193/

Attempt to index local 'actor' failure
http://45.55.195.193/viewtopic.php?f=73&t=14114
Page 1 of 1

Author:  Aspect [ Mon Mar 30, 2009 6:55 am ]
Post subject:  Attempt to index local 'actor' failure

Code:
SYSTEM: Activity "Command Center" was successfully started
ERROR: no overload of  'AHuman:AddInventoryItem' matched the arguments (AHuman, nil)
candidates are:
AHuman:AddInventoryItem(MovableObject*)

ERROR: Bedrock.rte/Assault.lua:141: attempt to index local 'actor' (a nil value)
ERROR: Bedrock.rte/Assault.lua:141: attempt to index local 'actor' (a nil value)
ERROR: no overload of  'AHuman:AddInventoryItem' matched the arguments (AHuman, nil)
candidates are:
AHuman:AddInventoryItem(MovableObject*)


That is the error, and this is what I believe to be the relevant code.
Code:
function AssaultMission:MakeActor(whichMode)
    local actor;
    local which = math.random();
    if which > 0.25 then
        actor = CreateAHuman("Soldier Light");
    else
        actor = CreateAHuman("Soldier Heavy");
    end

    local gun;
    which = math.random();
    if which > 0.80 then
        gun = CreateHDFirearm("Shotgun");
    elseif which > 0.50 then
        gun = CreateHDFirearm("Assault Rifle");
    elseif which > 0.40 then
        gun = CreateHDFirearm("Compact Rifle");
    elseif which > 0.15 then
        gun = CreateHDFirearm("Sniper Rifle");
    elseif which > 0.5 then
        gun = CreateHDFirearm("Compact Cannon");
    else
        gun = CreateHDFirearm("Flak Cannon");
    end
   
    local tool;
    which = math.random();
    if which > 0.85 then
        tool = CreateHDFirearm("Pulse Digger");
    elseif which > 0.75 then
        tool = CreateHDFirearm("Grenade Launcher");
    elseif which > 0.35 then
        tool = CreateTDExplosive("Frag Grenade");
    elseif which > 0.30 then
        tool = CreateHDFirearm("Concrete Gun");
    elseif which > 0.29 then
        tool = CreateTDExplosive("Stone");
    end
   
   local sidearm;
    which = math.random();
    if which > 0.70 then
        sidearm = CreateHDFirearm("Pistol");
    elseif which > 0.50 then
        sidearm = CreateHDFirearm("Auto Pistol");
    elseif which > 0.40 then
        sidearm = CreateHDFirearm("Auto Shot Pistol");
    end
   
    actor:AddInventoryItem(gun);
    actor:AddInventoryItem(tool);
    actor:AddInventoryItem(sidearm);
    actor:SetControllerMode(Controller.CIM_AI, -1);
    actor.AIMode = whichMode;
    return actor;
end


   if(defendspawntimer:IsPastSimMS(RespawnTimeDefense)) then
      if(basecontrol == 0) then
         local ship = CreateACDropShip("Drop Ship MK1");
            local actor = self:MakeActor(Actor.AIMODE_GOTO);
         ship:AddInventoryItem(actor);
         actor = self:MakeActor(Actor.AIMODE_GOTO);
         actor:ClearAIWaypoints();
         actor:AddAISceneWaypoint(Vector(defensemove:GetRandomPoint().X, defensemove:GetRandomPoint().Y));
         ship:AddInventoryItem(actor);
            ship.Pos.X = defendlz:GetRandomPoint().X;
         ship.Pos.Y = 0;
         ship.Team = self.Team_1;
         ship:SetControllerMode(Controller.CIM_AI, -1);
         MovableMan:AddActor(ship);
         defendspawntimer:Reset()
      end
   end



I don't know why the indent is different for "local actor =" or "ship.Pos.X ="
They are all the same indent.

sorry for the giant block of code, I would've posted less but I don't know where the problem even is!
This code is pretty much all taken from the zombie cave mission and I don't really even have a clue as to how it works, so any help would be appreciated.

Author:  zalo [ Mon Mar 30, 2009 2:36 pm ]
Post subject:  Re: Attempt to index local 'actor' failure

When defining a weapon, you need to include the .rte that it comes from (unless it is the Base.rte).

I believe a lot of those weapons you are trying to define come from "Coalition.rte".

Check out Klone Soccer for an example, since I can't pull it off the top of my head.

I hope that helps.

Author:  Aspect [ Mon Mar 30, 2009 5:05 pm ]
Post subject:  Re: Attempt to index local 'actor' failure

oh, should've noticed that..
thanks for the help.

edit: hmm, that doesn't seem to be my error.
now I am getting:
Code:
ERROR: the attribute 'ACDropShip.Team' is of type: (number)
and does not match: (nil)
ERROR: no overload of  'AHuman:AddInventoryItem' matched the arguments (AHuman, nil)
candidates are:
AHuman:AddInventoryItem(MovableObject*)

Author:  Lord Tim [ Tue Mar 31, 2009 2:28 am ]
Post subject:  Re: Attempt to index local 'actor' failure

Instead of going "function AssaultMission:MakeActor(whichMode)", just use "function MakeActor(whichMode)", and reference it by that. I am pretty sure that "self" is not the same as the mission.

Author:  Aspect [ Tue Mar 31, 2009 3:45 am ]
Post subject:  Re: Attempt to index local 'actor' failure

oh, I didn't notice that. I have to be more careful when I copy my code :/
but I am still getting the same error... I don't understand what
Code:
ERROR: no overload of  'AHuman:AddInventoryItem' matched the arguments (AHuman, nil)
candidates are:
AHuman:AddInventoryItem(MovableObject*)

means

Author:  Camalaio [ Tue Mar 31, 2009 4:20 am ]
Post subject:  Re: Attempt to index local 'actor' failure

I gotta make this quick, sorry if it doesn't make much sense.
I believe your problem, just by glancing at the code, is that sometimes you are not assigning a tool or sidearm. If you look at the if statement for the gun, it has an else statement to handle if the random numbers are below the lowest values in the if's and elseif's. Tools will not handle a random number under 0.29, and sidearms will not handle under 0.4. If one of these conditions is true, you are trying to add null (nil) to the inventory.

Basically: Throw in the else statements, see i it works.

Author:  Daman [ Tue Mar 31, 2009 6:03 pm ]
Post subject:  Re: Attempt to index local 'actor' failure

You're leaving tool/sidearm as nil if it's below a certain amount. You need the last else statement in this for tool and sidearm:

Code:
    if which > 0.80 then
        gun = CreateHDFirearm("Shotgun");
    elseif which > 0.50 then
        gun = CreateHDFirearm("Assault Rifle");
    elseif which > 0.40 then
        gun = CreateHDFirearm("Compact Rifle");
    elseif which > 0.15 then
        gun = CreateHDFirearm("Sniper Rifle");
    elseif which > 0.5 then
        gun = CreateHDFirearm("Compact Cannon");
    else
        gun = CreateHDFirearm("Flak Cannon");
    end



The error really tells you all you need to know.

Quote:
ERROR: no overload of 'AHuman:AddInventoryItem' matched the arguments (AHuman, nil)

Quote:
actor:AddInventoryItem(tool);

Author:  Aspect [ Thu Apr 02, 2009 1:19 am ]
Post subject:  Re: Attempt to index local 'actor' failure

oh yeah, this was fixed for me by mail2345 a while ago. If you wanna see the finished project go to scenes.

Page 1 of 1 All times are UTC [ DST ]
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group
http://www.phpbb.com/