Starrynite120
Prince
- Joined
- Jul 15, 2015
- Messages
- 472
I'm getting an error in this function that I do not understand why I am getting.
The error is:
What am I getting a nil value error?
To give some background to what I'm trying to do, I'm trying to detect if each player has certain playerperks and then declare them winner if they have the right ones. Its my attempt at a new victory condition. (I know the others are done through quests, which I may try and do instead once I get this one working.)
Code:
function GetPoints()
local Points = 1 --ERROR 1
local PLAYERPERK = GameInfo.PlayerPerks["PLAYERPERK_KNOWLEDGE_1"].ID;
local PLAYERPERK2 = GameInfo.PlayerPerks["PLAYERPERK_INDUSTRY_1"].ID;
local Player = Players[playerID];
if (Player:HasPerk(PLAYERPERK)) then --ERROR 2
Points = Points + 1
end
if (Player:HasPerk(PLAYERPERK2)) then
Points = Points + 1
end
if (Points > 2) then
Game.SetWinner(Players[Game.GetActivePlayer()]:GetTeam(), GameInfo.Victories["VICTORY_TIME"].ID);
else
Points = 1
end
end
GameEvents.PlayerDoTurn.Add(GetPoints);
The error is:
Code:
Runtime Error: C:\Users\Starrynite120\Documents\My Games\Sid Meier's Civilization Beyond Earth\MODS\Mods\Into the Nebula (v 1)\Victories/StarryNitePointVictory.lua:116: attempt to index a nil value
stack traceback:
C:\Users\Starrynite120\Documents\My Games\Sid Meier's Civilization Beyond Earth\MODS\Mods\Into the Nebula (v 1)\Victories/StarryNitePointVictory.lua:116: in function 'GetPoints'
stack traceback:
C:\Users\Starrynite120\Documents\My Games\Sid Meier's Civilization Beyond Earth\MODS\Mods\Into the Nebula (v 1)\Victories/StarryNitePointVictory.lua:111: in function 'GetPoints'
What am I getting a nil value error?
To give some background to what I'm trying to do, I'm trying to detect if each player has certain playerperks and then declare them winner if they have the right ones. Its my attempt at a new victory condition. (I know the others are done through quests, which I may try and do instead once I get this one working.)