View unanswered posts | View active topics It is currently Thu Dec 26, 2024 4:11 pm



Reply to topic  [ 8 posts ] 
 Attempt to index local 'actor' failure 
Author Message
User avatar

Joined: Mon Apr 28, 2008 1:35 am
Posts: 383
Reply with quote
Post 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.


Mon Mar 30, 2009 6:55 am
Profile

Joined: Sat Feb 03, 2007 7:11 pm
Posts: 1496
Reply with quote
Post 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.


Mon Mar 30, 2009 2:36 pm
Profile WWW
User avatar

Joined: Mon Apr 28, 2008 1:35 am
Posts: 383
Reply with quote
Post 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*)


Mon Mar 30, 2009 5:05 pm
Profile
User avatar

Joined: Fri Apr 27, 2007 4:55 pm
Posts: 1178
Location: America!
Reply with quote
Post 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.


Tue Mar 31, 2009 2:28 am
Profile
User avatar

Joined: Mon Apr 28, 2008 1:35 am
Posts: 383
Reply with quote
Post 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


Tue Mar 31, 2009 3:45 am
Profile

Joined: Fri Apr 06, 2007 10:11 pm
Posts: 45
Reply with quote
Post 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.


Tue Mar 31, 2009 4:20 am
Profile WWW
User avatar

Joined: Fri Jan 26, 2007 3:22 am
Posts: 1451
Reply with quote
Post 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);


Tue Mar 31, 2009 6:03 pm
Profile
User avatar

Joined: Mon Apr 28, 2008 1:35 am
Posts: 383
Reply with quote
Post 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.


Thu Apr 02, 2009 1:19 am
Profile
Display posts from previous:  Sort by  
Reply to topic   [ 8 posts ] 

Who is online

Users browsing this forum: No registered users


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group.
Designed by STSoftware for PTF.
[ Time : 0.042s | 14 Queries | GZIP : Off ]