Hi,
Can anyone suggest what is wrong with the following code fragment?
The pcall if statement always returns false giving the "not possible" output.
If I remove the pcall then it works fine until I target something without morale such as a crafting node and then I get:
...\Main.lua:120: attempt to call method 'GetMorale' (a nil value)
Code:
refPlayer = Turbine.Gameplay.LocalPlayer.GetInstance();
playerTarget = Turbine.UI.Label();
playerTarget .MaxMorale = 1;
playerTarget .CurMorale = 1;
if ( refPlayer:GetTarget() ~= nil ) then
if pcall( refPlayer:GetTarget():GetMorale() ) then
playerTarget.CurMorale = refPlayer:GetTarget():GetMorale();
playerTarget.MaxMorale = refPlayer:GetTarget():GetMaxMorale();
Turbine.Shell.WriteLine(" Updated target morale");
else
Turbine.Shell.WriteLine(" Not possible to get target morale");
end
else
Turbine.Shell.WriteLine(" No target selected");
end
What I am trying to achieve is :
Code:
if PLAYER_TARGET_NOT NULL
if TARGET HAS MORALE
GET_MORALE_AND_STORE_LOCALLY
else
DO_NOTHING
end if
end if
and it should do this without generating errors that crash the plugin