Xor Controller: invalid

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

Type: 
  • boolean

Values:

  • 1 = True = object isn't valid
     
  • 0 = False = object is valid

Example:

  • 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.
Xor Controller:
  • A python controller is needed to run the python script used to access any actuators connected to a Controller
Sample Code: Part 1


################  save controller as a global variable
 
# import bge module

import bge

# get the python controller
# Note: My Python controller and Xor controller are attached to same game object

python_controller = bge.logic.getCurrentController()

# get the game object that owns the controller
obj = python_controller.owner

# get the Xor Controller attached to the game object
# my Xor Controller is named Xor_1
xor_controller = obj.controllers["Xor_1"]

# save the object as a global variable
bge.logic.globalDict["Xor_1"] = xor_controller
 
Sample Code: Part 2

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

# import bge module
import bge

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

# invalid == False.  Xor Controller still exists
cont = bge.logic.globalDict["Xor_1"]