Real Noob python controller question

Folks,

I’m new to blender game engine and need help.

I have an IPO animation sequence for an object which is say 240 frames. I want to play 24 frames of the animation at a time.

At the moment, I have multiple keyboard sensors rigged to their own controller and IPO play actuators, which play the appropriate set of frames.

What I would like is to rig the space bar so that each time it is pressed, the next 24 frames are played i.e. in pseudocode :

Property Int framecount 0

Sensor : Keyboard Space Bar
Controller: python (framecount = framecount + 24)
Actuator : IPO Play (Start : Framecount) (Stop : Framecount+23)

I have looked at some of the built in scripts and can’t work out how to do this. Any help would be much appreciated!

I havent tryed this yet but will if i get time later today. if you get to it first let me know if there any problems. which of course there will be.
also make sure the indents are correct when you past it. I marked the blocke with
#--------------------- o help with this.

#ipoStep.py

Load the GameLogic Module

import GameLogic
import GameKeys
#------------------------------------------------------------
def stepIpo( step ):

# Get ipo actuator
ipoGo = controller.getActuator("IpoMove")
# Get the owner
owner = controler.getOwner()

#the object this script is attached to must have a
# int property defined for it named Step set to the
# of frames to step


frameStep = owner.getStep()

startFrame = ipoGo.getFrame()
endFrame = startFrame + frameStep


# KX_FALSE may need to be KX_TRUE
# i dont know what it means to treat the ipo as a force
# exactly

ipoGo.set("Play", startFrame , endFrame , KX_FALSE)

#-----------------------------------------------------------------

#status
KX_NO_INPUTSTATUS = 0
KX_JUSTACTIVATED = 1
KX_ACTIVE = 2
KX_JUSTRELEASED = 3
############# Get the controllers and sensors

Get controller you attached this python script to

controller = GameLogic.getCurrentController()

Get keyboard sensor

KeyBoard = controller.getSensor(“KeyBoard”)

keylist = KeyBoard.getPressedKeys()

scan for keys

#--------------------------------------------------
for key in keylist:
# key[0] == GameKeys.keycode, key[1] = status
#-------------------------------------
if key[0] == GameKeys.SPACEKEY:
#--------------------------------
if key[1] == KX_JUSTACTIVATED:
stepIpo()
#---------------------------------
#--------------------------------------
#--------------------------------------------------

stepIpo(step) should be stepIpo()

just noticed that.

well i tested it and this is what finaly works. it may not be parsed the best way but is works and should provide a starting point for what you want to do. I have not programed the ipo actuator before so my first guess (which was before my first cup of coffee) was a little wild.

#ipoStep.py

Load the GameLogic Module

import GameLogic
import GameKeys
#------------------------------------------------------------
def stepIpo( ):

#the object this script is attached to must have a
# int property defined for it named Step set to the
# number of frames to step

frameStep = owner.Step

startFrame = ipoGo.getEnd()
endFrame = startFrame + frameStep

ipoGo.setStart(startFrame)
ipoGo.setEnd(endFrame)

GameLogic.addActiveActuator(ipoGo, True)

print startFrame

print endFrame

#-----------------------------------------------------------------

#status
KX_NO_INPUTSTATUS = 0
KX_JUSTACTIVATED = 1
KX_ACTIVE = 2
KX_JUSTRELEASED = 3
############# Get the controllers and sensors

Get controller you attached this python script to

controller = GameLogic.getCurrentController()

Get keyboard sensor

‘’’ , not set

All keys set

KeyBoard = controller.getSensor(“KeyBoard”)

Get ipo actuator

ipo actuator set to play mode

ipoGo = controller.getActuator(“IpoStep”)

Get the owner

owner = controller.getOwner()

keylist = KeyBoard.getPressedKeys()

scan for keys

#--------------------------------------------------
for key in keylist:
# key[0] == GameKeys.keycode, key[1] = status
#-------------------------------------
if key[0] == GameKeys.SPACEKEY:
#--------------------------------
if key[1] == KX_JUSTACTIVATED:
stepIpo()
#---------------------------------
#--------------------------------------
#--------------------------------------------------

cxevalo.

Thanks so much. You’ve done all the hard work for me! I’ve been reading a little about Python and I think I’m going to try learning it.

My project is to build a virtual presentation environment in Blender that will knock the socks off Powerpoint and Keynote. I will export my slides and export them as bitmaps, and then use UV mapping to map them onto ‘tiles’ in the presentation environment.

I can’t believe this technique is not being used more widely!

Ninjagaiden

You are welcome
Good luck with your project. Python is worth knowing aside from its use in blender. It is a fantastic tool for any number of things.

cxevalo

Yes I am starting to realise that. What with Python in Blender, pyOGRE, and the python wrapper for VTK, I think I’ll be able to use it for all my graphics needs.

Finding a good tutorial for my odd Pascal / Delphi background is another matter though!