Skip to content

Commit

Permalink
[Player] Prevent nil lua error (esp. during loading)
Browse files Browse the repository at this point in the history
  • Loading branch information
aethys256 committed Oct 14, 2017
1 parent 41d71f9 commit bfba315
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 8 deletions.
16 changes: 10 additions & 6 deletions AethysCore/Class/Unit/Player/Instance.lua
Original file line number Diff line number Diff line change
Expand Up @@ -66,14 +66,18 @@
local GetInstanceInfo = GetInstanceInfo;
local function _GetInstanceInfo () return {GetInstanceInfo()}; end
function Player:InstanceInfo ()
local Infos = Cache.Get("UnitInfo", self:GUID(), "InstanceInfo", _GetInstanceInfo);
if Infos then
if Index then
return Infos[Index];
else
return unpack(Infos);
local GUID = self:GUID();
if GUID then
local Infos = Cache.Get("UnitInfo", GUID, "InstanceInfo", _GetInstanceInfo);
if Infos then
if Index then
return Infos[Index];
else
return unpack(Infos);
end
end
end
return nil;
end
end

Expand Down
8 changes: 6 additions & 2 deletions AethysCore/Class/Unit/Player/Main.lua
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,12 @@
local UnitID;
local function _UnitRace () return select(2, UnitRace(UnitID)); end
function Player:Race ()
UnitID = self.UnitID;
return Cache.Get("UnitInfo", self:GUID(), "Race", _UnitRace);
local GUID = self:GUID();
if GUID then
UnitID = self.UnitID;
return Cache.Get("UnitInfo", GUID, "Race", _UnitRace);
end
return nil;
end
end

Expand Down

0 comments on commit bfba315

Please sign in to comment.