Thoughts and tutorials on programming

Tuesday, October 31, 2006

how to import external modules

Say module is in e:\blender\shared\folder\
in blender do (in a script)
then from folder.file import whateverStuffYouWantLikeFunctionNames

Good luck!

more code snippets how to get active_camera, getSensors of an object

import GameLogic
print dir(GameLogic)

print "current scene is "
liveScene = GameLogic.getCurrentScene()
#print dir(liveScene)
print "now from that here is the camera:"
print dir(liveScene.active_camera)

#for o in liveScene.getObjectList():
# print dir(o)

me = GameLogic.getCurrentController()

print "controller"
print dir(me)
print "sensors:"
for obj in me.getSensors():
print dir(obj)

disappearing blender objects

So it appears that right now if a node has an IPO associated with it AT ALL then it will apply frame 1 of that IPO at the initiation of a game. Whether you like it or not. So if your camera 'disappears' every time or your object jumps at the beginning of a game... :-)

Monday, October 30, 2006

Random Blender notes

Blender Game Engine notes:

import GameLogic
GameLogic.myVar = 3

liveScene = GameLogic.getCurrentScene()
obj = liveScene.getObjectList()["OBCube"]

With the game engine, there seems to be no way to have a script that is fired with two actuators -- i.e. if this AND this then fire this script. Doesn't work. One way around this would be to revamp the GUI system to have another "column" that is logic connectors. like "add a logic connector "AND" or what not. Then you could use those with the normals and with these.

constraints are NOT reflected at 'game time' in the GameEngine. Parent/child objects are.

right now if you restart a scene, it reruns all scripts that have the "quotes" both unchecked (which hmakes them 'init' scripts).
Ways to instantiate 'once' in the GameEngine:

with solid variables:

print == ""
except AttributeError: = "init value"
print "done"

# the above way just makes it possible to not have the script crash, as it would typically do if you checked if the variable bbc existed or had been instantiated.

--there may be others.

Note IPO's for the GameEngine are by frame count, not by frame, so if you have a faster or slower out.

Also it would be nice to have more flexible IPO actuators--i.e. they can change IPO (the name) within the one object (the IPO referring to that object), and another would be then that more objects could use more than one IPO.

That's my notes so far!


With blender mouse actuators, say you have a mouse left actuator attached to a python script. The actuator will fire the python script TWICE per click--once when you click down, once when you click up. So this basically requires you to double check actuatorName.isActive() every time- - just having it fire does not mean what you think it might.

Friday, October 20, 2006

Blender GameLogic IPO's seems that IPO's have some interesting actions, if you change them 'on the fly' while they are being applied to an object.

The normal "thing" for IPO actuators to do is to just play through, then stop.
Let me explain. If you set your IPO to be "play" and you start it, if you tell that actuator to start up again, and it has not finished playing, it will NOT restart--it ignores the command to (re) start and just continues playing. Until it stops. Then it will "allow" the actuator command to re-start it.

Also, about IPO's (background)
each object can only play the (single) IPO that was last associated with it (though I think it may be possible to "link" it to others, it only really uses, for the game engine, the last one you assigned to it).

Currently, if an IPO object is "playing" you can't re-start it. And here is what happens if you change the
1) Begin frame (this is like an interruptive change fo the begin frame, or during playback). This will cause the currrent frame to 'jump' to an offset of the amount that you changed it by. Useful? Perhaps. more of an accidental "feature" I think. 2
2) End frame. If you change the end frame while in playback it will do nothing besides perhaps continue farther or shorter to that end frame. if, however, the IPO had already finished playing (stopped), THEN you changed the end frame, it would just 'skip' to that frame. Almost like assigning the IPO to the new end frame (it thought that you were at the end frame--the end frame changed. It changed you to still be at the end frame).
So nothing too bad.

First Blender thoughts

So...variables in the Blender GameEngine
Here are some things I have noticed over the last few days.

1) you can edit 'properties' of an object on the fly, thus (you don't need an actuator :-) )
import GameLogic
owner = GameLogic.getCurrentController().getOwner() # there might be a better way than this.
owner.propertyname = "newValue"

2) These properties 'reset' when you start or re-start a scene.