update script templates for new BGE api attributes

This commit is contained in:
Campbell Barton 2009-05-11 00:19:55 +00:00
parent 9cc61dd9c8
commit da3bdefb7a
2 changed files with 28 additions and 28 deletions

@ -29,58 +29,58 @@ def main():
cont = GameLogic.getCurrentController()
# The KX_GameObject that owns this controller.
own = cont.getOwner()
own = cont.owner
# for scripts that deal with spacial logic
own_pos = own.getPosition()
own_pos = own.worldPosition
# Some example functions, remove to write your own script.
# check for a positive sensor, will run on any object without errors.
print 'Logic info for KX_GameObject', own.getName()
print 'Logic info for KX_GameObject', own.name
input = False
for sens in cont.getSensors():
for sens in cont.sensors:
# The sensor can be on another object, we may want to use it
own_sens = sens.getOwner()
print ' sensor:', sens.getName(),
if sens.isPositive():
own_sens = sens.owner
print ' sensor:', sens.name,
if sens.positive:
print '(true)'
input = True
else:
print '(false)'
for actu in cont.getActuators():
for actu in cont.actuators:
# The actuator can be on another object, we may want to use it
own_actu = actu.getOwner()
print ' actuator:', actu.getName()
own_actu = actu.owner
print ' actuator:', actu.name
# This runs the actuator or turns it off
# note that actuators will continue to run unless explicitly turned off.
if input:
GameLogic.addActiveActuator(actu, True)
cont.activate(actu)
else:
GameLogic.addActiveActuator(actu, False)
cont.deactivate(actu)
# Its also good practice to get sensors and actuators by names
# so any changes to their order wont break the script.
# Its also good practice to get sensors and actuators by name
# rather then index so any changes to their order wont break the script.
# sens_key = cont.getSensor('key_sensor')
# actu_motion = cont.getActuator('motion')
# sens_key = cont.sensors['key_sensor']
# actu_motion = cont.actuators['motion']
# Loop through all other objects in the scene
sce = GameLogic.getCurrentScene()
print 'Scene Objects:', sce.getName()
for ob in sce.getObjectList():
print ' ', ob.getName(), ob.getPosition()
print 'Scene Objects:', sce.name
for ob in sce.objects:
print ' ', ob.name, ob.worldPosition
# Example where collision objects are checked for their properties
# adding to our objects "life" property
"""
actu_collide = cont.getSensor('collision_sens')
for ob in actu_collide.getHitObjectList():
actu_collide = cont.sensors['collision_sens']
for ob in actu_collide.objectHitList:
# Check to see the object has this property
if hasattr(ob, 'life'):
own.life += ob.life

@ -1,7 +1,7 @@
#!BPY
"""
Name: 'GameLogic Template'
Blender: 245
Blender: 249
Group: 'ScriptTemplate'
Tooltip: 'Basic template for new game logic scripts'
"""
@ -14,15 +14,15 @@ script_data = \
def main():
cont = GameLogic.getCurrentController()
own = cont.getOwner()
own = cont.owner
sens = cont.getSensor('mySensor')
actu = cont.getActuator('myActuator')
sens = cont.sensors['mySensor']
actu = cont.actuators['myActuator']
if sens.isPositive():
GameLogic.addActiveActuator(actu, True)
if sens.positive:
cont.activate(actu)
else:
GameLogic.addActiveActuator(actu, False)
cont.deactivate(actu)
main()
'''