Actuator Logic Brick: invalid

invalid
  • Returns whether or not a reference to an object (KX_GameObject, SCA_ILogicBrick, KX_Scene, etc.) is invalid or not.

Return Type: 

  • boolean
  • 1 = True = object isn't valid
  • 0 = False = object is valid
Note:
  • Pointers to game data can be stored as a global variable.
     
  • If the game object is freed/deleted/destroyed, the global variable holds a pointer to game data that no longer exists.
     
  • Trying to access this data will raise a system error.
     
  • invalid allows you to test for this case without raising the system error.
Sample Code: Part 1


################  save actuator reference as a global variable
 
# import bge module

import bge

# get the python controller
cont = bge.logic.getCurrentController()

# get the sensor named Act_1
act = cont.Actuators["Act_1"]

# save actuator reference as a global variable
bge.logic.globalDict["Act_1"] = act
 
Sample Code: Part 2


################  Check if the saved reference is invalid

# import bge module
import bge

# check if saved actuator reference is invalid
if bge.logic.globalDict["Act_1"].invalid == False:

# invalid == False.  Act_1 still exists
act = bge.logic.globalDict["Act_1"]