noob needs script to cause reset to original game engine startup view

I’m new to Blender, don’t know Python, and am using B v2.49.

I’m trying to make a model viewer using the Game Engine, and would like to provide that the user could cause a reset to how the model originally presented at startup. I think I know how to begin to allow for a script to do that via the logic bricks, though I don’t know how to write the script to actually do it.

At present, the model is only allowed to be rotated by user, so all I need right now is to reset rotation (of parent emptymesh) to original orientation. (Later, if I provide “exploded view” capability, I’d have to reset individual objects to original positions)

From reading tutorials etc and some help from others, I think what I need would be a script which:

  1. checks to see if it’s been run before or not, and,
  2. if not run before, gets current (initial) orientation of an emptymesh (all other objects are parented by it, so they should follow whatever is done to it, I think), saves that info in some way which can be accessed by future execution of script, and does nothing else;
  3. if has run before, then does not get current orientation of enpty mesh, but does retrieve previous initial orientation info, and uses that info to set emptymesh orientation to that initial condition.

Can anyone show me what such a script would look like?

(I’m trying to do it with a script because when I tried using a logic actuator to Restart Scene, for some reason it takes about 10 seconds to accomplish this, and I’m hoping a “simple” rotation would happen much quicker, as rotating in the BGE does work fine/quickly)

hi OlderNoob,

at init time, you could store the starting orientation of your empty in a game dictionnary (the value will be kept during the game)
then add a keyboard sensor that runs a script that apply the stored orientation.

will make a little .blend.

ps : the game engine API is almost the same on 2.5, and its faster… maybe you should use it from now ?

space to reset
jerome.le.chat.free.fr/tmp/olderLearner.blend

Thanks littleneo, that seems to work fine! Now I’ll try adapting it to my model, and see if I can avoid messing your script up in the process!

And I’ll take your suggestion to move to 2.5 under advisement, particualarly if BGE does run faster.

ps. where in your reset script code or logic block parameters did <spacebar> become the activating key for reset?

in the logic panel, in the middle, above the controllers there’s a set a buttons called ‘states’

one has a black dot in it, meaning it will be one of the initial state at startup
( ctrl leftclic on the state button to change you can set several states as initial )

the actuator you see in this initial state tells BGE to switch to state 2 once the init script has been red.
state2 is where the object is rotating (where the game is actually running)
whereas state1 is only used one time at startup, just to run the init script

if you clic the state 2 button above the controllers, you’ll see the config with the spacebar sensor and the reset script attached to it.

thank you littleneo, I got it to work!

I had to mess with it, because I’m letting user selectivly rotate a set of objects around an empty mesh, so I removed the auto-rotation.
But one of the things I don’t understand about your solution is that I had to add more controllers to state two in order to link my <lrud >arrows to the left,right,up,down actions. I’m wondering why the controlers from state 1 didn’t just carry over into state 2, like the related actuators did.

Here’s state 1 and state 2 screenshots, in case that helps:

state 1:


state two:


And when I later add some movement to the objects (exploded view), how might I set that up to return to original condition?
I’m guessing very similar code, just replace “ow.worldOrientation” with something relating to translation/movement?

the ‘rlud’ sensors in state 1 are useless, since BGE will stay in state 1 only one ‘tic’ then go to state 2 : remove the corresponding CONTROLLERS from it (cont1…cont4) they are only usefull in state 2.

I don’t understand what you mean by ‘(exploded view)’

I think you should read a bit of documentation about state concept you miss smtg important a bit long to explain here.
the state copy actuator defines which state must be run.
for 1 tic, state 1 is run
for the other ‘tics’ it will stay in state 2
states are executed apart, the state actuator define which one must be executed at the next tic.
http://www.tutorialsforblender3d.com/GameDoc/LogicBricks/Controller_1.html

ow is a pointer to the empty object.
ow.name will give you its name.
ow.xxxx will do something on your object or send back a value. see here :
http://www.tutorialsforblender3d.com/GameModule/ClassKX_GameObject.html

BGE programming :
http://www.tutorialsforblender3d.com/Python/Python_index.html
see game engine section here also… :wink:

Thank you littleneo, you’ve been very helpful!

By “exploded view” I mean that the parts which comprise some structure are moved away from one another in some reasonable way such that one can sbetter ee how they fit and function together. For instance, imagine a differential, or an automatic or manual transmission of an automobile: if you look at a drawing of the outside of one of those, neither its components nor their interactive functioning are visible; so, instead, draw it “taken apart”, but such that parts which were in some way connected are drawn some distance apart but still close to one another, to show how they would fit together if they were moved back together.

So, my question would be, if I have a structure which is comprised of many individual parts, and I allow the game user to move those parts away from one another, then how could I allow the user to make all those parts “reset” back to how the structure looked to begin with on entry to the BGE, by a simple button press?

I would use an armature* :
like a piovra. at each tentacle you parent one of the part.
select object / shift select armature object / enter pose mode / select bone / ctrl-P / parent to bone

and you setup some action/animation for each part/tentacle. 2 action for each (key only the responsible bones in each corresponding action) : one to go apart, one to go back to initial state.
then keys associated to each ‘partX goes apart’ action actuator.
and one key to reset all the animation, connected to every ‘goback’ animations. between back keys and back action, a script checks which part need to go back, and activate the corresponding action.
something like that.
(for a first script it’s a bit complicated maybe, have some training one the files in tutorialforblender and in the BGE section)

ok, thanks again.