Help coding a Python menu script

I´m trying to code some Python into a Game Blender menu and got into a few newbie´s brickwalls.
If someone could help me code this…

I have a menu (a map) with some 100 hot sopts (planes). When the user clicks into one, the camera gets set to some position elsewhere.
I was thinking into coding it like this:

|Hotspot |---------| Python script |

  • all hotspots are linked to the same script.
  1. The code would check the hotspot name and based on that get the position and orientation of a similar named Empty on the scene.
    Like Hotspot.somename would check for Empty.somename properties.

  2. Then the script set the the Camera empty to the position and orientation of the checked empty.

The problem is:

  • I dont know how to set some spefific obj pos and ori. I can only do it to a “own” right now…
  • How do I process the clicked name (Hotspot.somename to strip the first 7 letters and compose the name Empty.somename?

Thanks! And sorry for such basic questions… :expressionless:

Did my homework and got this far: :smiley:

import GameLogic
co=GameLogic.getCurrentController()

print "Script Click Position"

ob=co.getOwner()
obName=ob.getName()
print " "
print "obName:"
print obName
print " "

emptyName=obName[6:]
print "empty sufix:"
print emptyName
print " "

emptyName= "Empty."+emptyName
print "emptyName:"
print emptyName
print " "

#error: pos=emptyName.getPosition()
print " "
print emptyName+" position: "
#print pos

These are the block with the remaining doubts:

How to get some obj position (?):
#error: pos=emptyName.getPosition()

How to set some obj position - I already know its name (EmptyPosicao) (?):
#error EmptyPosicao.setPosition(pos)[/

I´m still strugling with this… Anyone?
Can I make a Python script change the position of an object not connected by Logic Bricks? How?

Prior to 2.34, no you can’t. I haven’t experimented much with the new api, but I think you can get objects through the scene module. Check out the official api documentation:

Scene module

Thanks, Saluk! I will try to implement that:

# get an object named 'Cube'
obj = scene.getObjectList()["OBCube"]

Perhaps a simpler way of doing this is to define the camera position/orientation across a series of frames using an IPO curve. A certain frame would define the camera position/orientation at a certain empty (though you wouldn’t need empties with this system).

You then use an IPO Property logic brick to set the camera’s position.

Andy, actually that´s the way I have it coded right now, but since I have hundreds of hotspots and IPO, it´s getting pretty complicated to administer. So I thought about this empty´s way. It would make it very clean to handle.
But I´m seeing this is not so easy (still I´m having a very good change to learn Python !!). Anyway, if this can´t be coded, I´ll go back to the IPO way, maybe integrating it in one Python script with a property IPO for all the hotspots (it´s separated and hard coded right now).

O OO OOO OOO (play the trumpets)!

Got it working fine! Thanks a lot for the input, guys! Having that knowledge will be very important to help build my Blender interactive projects!

Here´s the code:

import GameLogic
co=GameLogic.getCurrentController()

#Checa MouseOver e Left Click
senLMB=co.getSensor("LMB")
senMouseOver=co.getSensor("MouseOver")
if senLMB.isPositive() and senMouseOver.isPositive():
	print " "
	print " "
	print " "
	print "*********************"
	print "Script Click Position"
	print "*********************"
 	print "Alexandre Rangel"
	print "www.3Dzine.com.br"

	ob=co.getOwner()
	obName=ob.getName()
	print " "
	print "Clicked hotspot obName:"
	print obName
	print " "

	emptyName=obName[6:]
	print "empty sufix:"
	print emptyName
	print " "

	emptyName= "OBEmpty."+emptyName
	print "emptyName:"
	print emptyName
	print " "

	# get the scene
	scene = GameLogic.getCurrentScene()
       
	#print all the objects in the scene
	print "All scene objects:"
	for obj in scene.getObjectList():
		print obj.getName()
		print obj.getPosition()


	# get an object named 'emptyName' 
	emptyObj = scene.getObjectList()[emptyName]
	print "emptyObj:"
	print emptyObj.getName()

	# gets empty position:
	pos=emptyObj.getPosition()
	print " "
	print emptyName+" position: "
	print pos
	print " "


	# gets empty orientation:
	ori=emptyObj.getOrientation()
	print " "
	print emptyName+" orientation: "
	print ori
	print " "


	#Sets camera empty position
	emptyPosicaoObj = scene.getObjectList()["OBEmpty.Posicao"]
	print " "
	print emptyPosicaoObj


	#pos:
	print " "
	print "emptyPosicaoObj Old Position:"
	print emptyPosicaoObj.getPosition()

	emptyPosicaoObj.setPosition(pos)

	print " "
	print "emptyPosicaoObj New Position:"
	print emptyPosicaoObj.getPosition()


	#ori:
	print " "
	print "emptyPosicaoObj Old Orientation:"
	print emptyPosicaoObj.getOrientation()

	emptyPosicaoObj.setOrientation(ori)

	print " "
	print "emptyPosicaoObj New Orientation:"
	print emptyPosicaoObj.getOrientation()
	

Why is that the last two blocks of code (#pos and #ori) output the same values for Old and New values ? Do I need some update command after the values are changed?
The behaviour of the scene is perfect. My curiosity is just these print commands not changing right away.

Me also learning Python but are you not setting pos/ori to their current values, ie, no change?

The game engine processes world stuff, then python, then world stuff, etc. So any commands that change the world wont take effect until the script ends. Such as setting an object’s position.

Ok. Thanks, Saluk.