[Bf-blender-cvs] SVN commit: /data/svn/bf-blender [20137] trunk/blender/release/scripts: update script templates for new BGE api attributes
Campbell Barton
ideasman42 at gmail.com
Mon May 11 02:19:56 CEST 2009
Revision: 20137
http://projects.blender.org/plugins/scmsvn/viewcvs.php?view=rev&root=bf-blender&revision=20137
Author: campbellbarton
Date: 2009-05-11 02:19:55 +0200 (Mon, 11 May 2009)
Log Message:
-----------
update script templates for new BGE api attributes
Modified Paths:
--------------
trunk/blender/release/scripts/scripttemplate_gamelogic.py
trunk/blender/release/scripts/scripttemplate_gamelogic_basic.py
Modified: trunk/blender/release/scripts/scripttemplate_gamelogic.py
===================================================================
--- trunk/blender/release/scripts/scripttemplate_gamelogic.py 2009-05-10 22:51:49 UTC (rev 20136)
+++ trunk/blender/release/scripts/scripttemplate_gamelogic.py 2009-05-11 00:19:55 UTC (rev 20137)
@@ -29,58 +29,58 @@
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
Modified: trunk/blender/release/scripts/scripttemplate_gamelogic_basic.py
===================================================================
--- trunk/blender/release/scripts/scripttemplate_gamelogic_basic.py 2009-05-10 22:51:49 UTC (rev 20136)
+++ trunk/blender/release/scripts/scripttemplate_gamelogic_basic.py 2009-05-11 00:19:55 UTC (rev 20137)
@@ -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 @@
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()
'''
More information about the Bf-blender-cvs
mailing list