Attempt to index field '?' when getting a player's [Solved]

In this forum you will find and post information regarding the modding of Star Wars Battlefront 2. DO NOT POST MOD IDEAS/REQUESTS.

Moderator: Moderators

Post Reply
Noobasaurus
Droid Pilot Assassin
Droid Pilot Assassin
Posts: 2006
Joined: Tue Aug 17, 2010 5:56 pm

Attempt to index field '?' when getting a player's [Solved]

Post by Noobasaurus »

So here's the relevant part of the lua.
Hidden/Spoiler:
[code]
OnTimerElapse(
function(timer)
if (GetNumTeamMembersAlive(2) + GetNumTeamMembersAlive(1)) >= 2 then
ShowMessageText("level.0TT.begin")
peopleAlive = ((GetNumTeamMembersAlive(2) + GetNumTeamMembersAlive(1)) -1)
local traitorNumber = math.random(0, peopleAlive)
print("traitornumber: ", traitorNumber)
if GetCharacterUnit(traitorNumber) then
print("1")
--local traitor = traitorNumber
print("1")
local traitorMatrix = GetEntityMatrix(GetCharacterUnit(traitorNumber))
print("1")
if GetCharacterTeam(traitorNumber) == 1 then
print("5")
traitorClass = unittablemaster1[traitorNumber + 1].unitclass
print("7")
elseif GetCharacterTeam(traitorNumber) == 2 then
print("6")
traitorClass = unittablemaster2[traitorNumber + 1].unitclass
print("8")
end
print("class: ", traitorClass)
local bodyMatrix = CreateMatrix(3.14159,0,-10,0,0,0,1, traitorMatrix)
SetEntityMatrix(GetCharacterUnit(traitorNumber), bodyMatrix)
KillObject(GetCharacterUnit(traitorNumber))
SelectCharacterTeam(traitorNumber, 4)
SelectCharacterClass(traitorNumber, traitorClass)
SpawnCharacter(traitorNumber, traitorMatrix)
ready = 1
--[[elseif GetTeamMember(2, traitorNumber) then
print("2")
local traitor = GetTeamMember(2, traitorNumber)
print("2")
local traitorMatrix = GetEntityMatrix(traitor)
print("2")
local traitorClass = unittablemaster2[traitor + 1].unitclass
print("2")
local bodyMatrix = CreateMatrix(3.14159,0,-10,0,0,0,1,GetEntityMatrix(GetCharacterUnit(traitor)))
print("2")
AddUnitClass(4, traitorClass, 1, 1)
print("2")
SetEntityMatrix(GetCharacterUnit(traitor), bodyMatrix)
print("2")
KillObject(GetCharacterUnit(traitor))
print("2")
SelectCharacterTeam(traitor, 4)
print("2")
SelectCharacterClass(traitor, traitorClass)
print("2")
SpawnCharacter(traitor, traitorMatrix)
print("2")
ready = 1--]]
end
-- playerInfo[peopleAlive].charTeam
StartTimer(check)
StartTimer(win)
ShowTimer(win)
SetTeamAsNeutral(1,1)
SetTeamAsNeutral(2,2)
DestroyTimer(timer)
SetReinforcementCount(1, 0)
SetReinforcementCount(2, 0)
end
end,
grace
)
[/code]
It all works fine except past the print("6"). For some reason, it can't grab the player's class. The other part, near the print("5"), runs just fine. Here's the error.

Code: Select all


Message Severity: 3
C:\Battlefront2\main\Battlefront2\Source\LuaHelper.cpp(312)
CallProc failed: (none):0: attempt to index field `?' (a nil value)
stack traceback:
	(none): in function <(none):145>

Also, here's the part of the lua that gets the classes, written by Mav.
Hidden/Spoiler:
[code]
function CompileUnitTables()

unittablemaster1 = {}
unittablemaster2 = {}

if SetHeroClass then

holdsetheroclass = SetHeroClass

SetHeroClass = function(...)
if arg[1] == 1 then
table.insert (unittablemaster1, {unitteam = arg[1], unitclass = arg[2]})
elseif arg[1] == 2 then
table.insert (unittablemaster2, {unitteam = arg[1], unitclass = arg[2]})
end

holdsetheroclass(unpack(arg))

end

end

if AddUnitClass then

holdaddunitclass = AddUnitClass

AddUnitClass = function(...)
if arg[1] == 1 then
table.insert (unittablemaster1, {unitteam = arg[1], unitclass = arg[2]})
elseif arg[1] == 2 then
table.insert (unittablemaster2, {unitteam = arg[1], unitclass = arg[2]})
end

holdaddunitclass(unpack(arg))

end

end

end
[/code]
It gets the classes for team 1 players fine, but it does not for team 2 players. Any ideas?
Last edited by Noobasaurus on Mon May 11, 2015 6:09 pm, edited 1 time in total.
User avatar
Locutus
1st Lieutenant
1st Lieutenant
Posts: 420
Joined: Fri Jun 04, 2010 10:08 am
Projects :: Stargate Battlefront Pegasus
Location: Germany
Contact:

Re: Attempt to index field '?' when getting a player's class

Post by Locutus »

What is the highest value peopleAlive can have?
Maybe you run out of classes for team 2?
Noobasaurus
Droid Pilot Assassin
Droid Pilot Assassin
Posts: 2006
Joined: Tue Aug 17, 2010 5:56 pm

Re: Attempt to index field '?' when getting a player's class

Post by Noobasaurus »

peopleAlive can be (theoretically) infinite. The whole mode is only meant for less than 20 people, though, so it shouldn't ever be too high.

I don't think that I ran out of classes for team 2, however, that does bring up an interesting point. It may have something to do with having 12 classes on one team, but I forgot what the max was. It was either 12 or 10 I think, and if it's 10 then this error might happen. However, I don't think that it would return this error; instead, it would say that the class wasn't on team 4.
razac920
2nd Lieutenant
2nd Lieutenant
Posts: 365
Joined: Sun Jan 16, 2011 12:42 am

Re: Attempt to index field '?' when getting a player's class

Post by razac920 »

There is a max of 10 classes per team, or 9 + 1 hero class.
Noobasaurus
Droid Pilot Assassin
Droid Pilot Assassin
Posts: 2006
Joined: Tue Aug 17, 2010 5:56 pm

Re: Attempt to index field '?' when getting a player's class

Post by Noobasaurus »

Ah, thanks! Solved the error.
Post Reply