Getting a object in another scene?

The title explains it. I got a list of scenes, but every time I try to get a individual scene I get errors, same thing on when I try to get a list of objects out of the scenes. What is the propper way of doing this? It’s obvious I am doing something wrong!!! Thanks in advance,

Get an object from another scene:


scene = GameLogic.getSceneList()["YourSceneName"]
object = scene.objects["<i><b>OB</b></i>ObjectName"] # you probably forgot the OB part

The first line gets a scene. The second gets the object. Make sure you remember the OB prefix. (Which will disappear in 2.5)

-Sunjay03

By the way, you should check out some game engine documentation.
http://www.blender.org/documentation/249PythonDoc/GE/index.html

Nope, it was this part I missed: [“YourSceneName”].
Hooray for sunjay! Thanks for the quick response!

Just something really stupid: scene = G.getSceneList()[‘GamePlay’] is giving me an error saying ‘list indices must be integers not strings’. What did I do wrong this time? I tried with parenthesies but no luck either?

Right…my fault. There is a problem with that function where for some reason it doesn’t use the CValueList…

Here is the function to get the scene:


## gets a scene from a list of scenes
def getScene(sceneName, list=GameLogic.getSceneList()):
	# go through every scene and check
	for scene in list:
		# check for a match
		if scene.name == sceneName:
			# return the correct scene
			return scene

Ok, thanks Sunjay! I will try it out in the morning, almost midnight where I live… I really hope they fix that soon, the first way looks like it would take a lot less time to type!

Well the second way you can just leave at the top of your code and then use the function “getScene” multiple times. Its really just as easy as the above…maybe even with less to write. :wink:

-Sunjay03

So, run the second script as usual, only use getScene() to acces the scenes it lists?

Yup. Just make sure that the function is above where ever you are calling it. (To avoid namespace errors)

-Sunjay03

I can’t quite get it to work. Here is my .blend, can you tell me what I am doing wrong? I have been trying for quite awhile, no luck:(

Attachments

WorkingScripts.blend (185 KB)