Sunday, 5 February 2012

Depreciated

Well I've had a lot of fun after the last two days. I did some python in the 2.4 days and I wasn't that good but I had it worked out. Of course in Blender 2.49b (my favourite release by the way) things changed and got 'depreciated'.

Well now I getting back on the GamesEngine thing with 2.61 and I now have to get to grips with the new stuff, that replaces the depreciated. And its been such a painful journey I thought I would document it for a change. So.......

This is really basic ( but it still took me ages to work it out from the documentation)

to get the list of controllers we still use - GameLogic.getCurrentController() - s0
ourControllers = GameLogic.getCurrentController()

then to get the sensor and the actuator we used to do
mySensor = ourControllers.getSensor("Mouse") - where Mouse is the title of the sensor
myActuator = ourControllers.getActuator("MoveThing") - where MoveThing is the title of the actuator

now you should do this:
mySensor = ourControllers.sensors["Mouse"]
myActuator = ourControllers.actuators["MoveThing"]

if the sensor was Mouse movement before you would have got the x direction movement by:
Xmovement = mySensor.getXPosition()

now, in 2.61 I have to write it like this:
Xmovement = mySensor.position[1]
here position is a list variable; it holds two values, firstly the x position then the y. the number in the square bracket denotes which of the variables we are reading, 1 for the first, 2 for the second.

Say our actuator is a Motion actuator (simple), we now write to it like this:
myActuator.dRot = [0, 0, 1]
so we are changing the rotational value which is a list like for position; x,y,z

To make the actuator actually do the thing we used to do this:
GameLogic.addActiveActuator(myActuator,1)

this is now written like this:
ourControllers.activate(myActuator)

and finally - how do we read and write to properties in 2.61?
we used to:
own = cont.getOwner() and then address the property by own.frameY
now do
owner = myControllers.owner and then own["frameY"] to address the property.

there you go. Hope it helps someone. let me know if its wrong

No comments:

Post a Comment