KX_GameObject, not str ERROR!!!

Here’s the stuff I posted up as a bug report. If it’s not a bug and there’s a new way to use setObject, I’m all ears. z3r0_d, I tried act.setAddObject(scene.getObjectList()[a string]) and it doesn’t seem to work. Hehe, and the docs are alien to me, somewhat %| .

Here’s the link to the .blend. I don’t have good webspace so copy the link and paste it in a new browser window.
http://www.geocities.com/blender3dsite/BugTest.zip
If you can get the file, skip all the instructions and go directly to read the last lines starting from “Hit p and…” If it doesn’t work, you can go on ahead and recreate the problem, it shouldn’t take longer than 2 minutes.

Ok, to recreate the problem. Add 4 empties in a line in layer 1, make sure they have a good amount of space between them. In layer 2 add a two cubes and name it, Box, Box0. Now go to the python script window, create a new txt file and name it, Add, and add this in.

import GameLogic

controller = GameLogic.getCurrentController()
owner = controller.getOwner()

#Lets you use that particular actuator
act = controller.getActuator(“act”)

act.setObject(‘Box0’)
GameLogic.addActiveActuator(act, 1)

Select the first empty and go to the logic bricks. Under sensor add an always sensor with pulse mode off. Under controllers add Python and type in Add as the script name. Under Actuators add Edit Object and make sure the actuator name is, act. Type in, Box, as the name for the parameter OB. Now all 4 empties will have the same logic so shift select the right 3 empties then shift select the 1st empty. Ctrl-C and choose logic bricks.

Hit p and 2.34 will only add 2 boxes instead of 4. In 2.33a and 2.25, the correct 4 boxes are added. In 2.34 the console window prints out

PYTHON SCRIPT ERROR:
TypeError: argument 1 must be KX_GameObject, not str

I call this a bug in 2.34.

Jason Lin

The problem:

Add Object Actuators now take KX_Gameobject(owner) as an argument instead of a string(objects name).
Scene.getObjectList() only gets the objects in active layers but, Add Object Actuators can only add objects from inactive layers.

hahaha

In other words, I can’t use that particular code? Err, by the way you said it, there seems to be no way I can add objects with the python code setObject. If Scene.getObjectList() can only get objects in active layers, how can I get objects from inactive layers?

So how can I make it so that my string can become a KX_GameObject so that the add Object Actuator can use it. In this case, I have a string: Box0. How can I make Box a KX_GameObject so I can use

act.setObject(‘Box0’)

Thanks.

Jason Lin

That’s a good Question. I would be interested on this, too. Why now that KX_… Thing? What was wrong with the String Solution?

I’ve tried that with Strings (like the old Style) and mostly it works. But sometimes i get the Error above and Blender crash. :frowning:

setObject is supposed to accept either an object reference or a string. Just doing a string is not enough because if you add copies of an object, they all have the same name. (I had a request for this…)

Well, the following code works for versions 2.25 and 2.33a of Blender. Multiple objects added with the same name using the edit object actuator is no problem in those 2 version mentioned above.

setObject is supposed to accept either an object reference or a string.

alien-xmp, so it doesn’t accept string currently? So is there a way to remedy this or do I wait for them to get to the Bug Report (meaning it’s actually a bug and there’s no new way to use setObject).

A funny thing to note. If you can get the file above, all 4 empties use the same code and if you run it, 2 boxes get added. So what’s going on there, the game engine only adds half of the objects. I find it strange that it works for half of the empties and doesn’t work for the other half.

Thanks.

Jason Lin

setObject is supposed to accept either an object reference or a string. Just doing a string is not enough because if you add copies of an object, they all have the same name. (I had a request for this…)

You can only add objects from the inactive layers to the active layers so why would it matter if you have added objects with the same name in active layers? It worked just fine when it accepted a string.

I did a similar test and mine actually crashes with a MSVC abnormal program termination message and this on the console:

Exception exceptions.TypeError: 'argument 1 must be KX_GameObject, not str' in '
garbage collection' ignored
Fatal Python error: unexpected exception during garbage collection

Please test it out, I’m curious to see if this is happening to other people.
http://s87416564.onlinehome.us/blender/bugs/addObj_bug.blend

I got exactly this Messages, too. dmao’s File crashing only on Game-Exit. As long as the Game is running, everything is fine.