-
It is a property. You can use a property sensor to evaluate the content.
-
Loops are necessary when you process several elements the same way. This is a basic processing not limited to games.
Example?
the inventory can be a collection for slots. You loop over all slots processing them slot by slot.
other example: checking sensor status:
import BGE
def actLikeAND():
if allSensorsPositive():
activateAllActuators()
else:
deactivateAllActuators()
def allSensorsPositive():
for sensor in bge.logic.getCurrentController().sensors:
if not sensor.positive:
return False
return True
def activateAllActuators():
controller = bge.logic.getCurrentController()
for actuator in controller.actuators:
controller.activate(actuator)
def deactivateAllActuators():
controller = bge.logic.getCurrentController()
for actuator in controller.actuators:
controller.deactivate(actuator)
more?
Searching for objects:
import bge
def findByPropertyName(propertyName):
return [object for object in bge.logic.getCurrentScene().objects
if propertyName in object]
def findByPropertyValue(propertyName, value):
return [object for object in bge.logic.getCurrentScene().objects
if propertyName in object and object[propertyName] == value]
- this behavior of a display. Typically whenever the status of something changes, you notify any interested listener. The listener reads the new status and shows it. There can be none, one or more listeners.
An option is to send a message.
A character gets damage, the damage dealer stores this damage in a property at the character and sends a message “damage received”.
A damage viewer text object associated with the character wakes up on message. It reads the damage from the property and shows it on screen for a while). Viewers listening for other messages (e.g. “health change”) will do nothing.
Optional: If the status change can be expressed as string, you can send the new status as message body.
I hope it gives some ideas.