Lua and XML: EvaluatePerception

The Lua script function EvaluatePerception allows your scripts to "see" outside of their own variables. The function accepts arguments of: perception name (string), player object (PlayerObject variable), AI target location (a game "cell") or AI target (a unit, planet, or appropriate).

These arguments are based on the content of the perception you want to evaluate. You should always pass PlayerObject, but the other variables are perception-dependent. For example: EvaluatePerception("Friendly_Land_Unit_Raw_Total", PlayerObject, priority_planet) from GalacticFreeStore.lua. The perception is:  Variable_Target.FriendlyForce.GroundTotalUnnormalized  So to evaluate this perception, the game needs a valid Variable_Target, in this case a planet, and the PlayerObject so it knows what counts as Friendly.

Note that here priority_planet is a GameObject taken from priority_planet = FindTarget.Reachable_Target(PlayerObject, "Ground_Priority_Defense_Score", "Friendly", "Friendly_Only", 0.1, object) if priority_planet then priority_planet = priority_planet.Get_Game_Object end because Reachable_Target doesn't return a GameObject. Note that Reachable_Target uses parameters that are the same as those used for Goals!