python: setting Object on addObject actuator

(lizard809) #1

say i want the actuator to add object Plane
all these won’t work


anyone got this to work?

(saluk) #2

The second one should be right.

Is the Plane in a hidden layer? The add object actuator won’t add it if its not in a hidden layer.

Did you spell plane right? “Plane” is different than “plane”

Did you fire the actuator? Just changing what object it’s going to add isn’t going to add it. You must also do this:
to actually tell the actuator to “go”

(lizard809) #3

i have every thing set up right, try making a file that does correctly, if you make it, PLEASE upload it, ive tried lots and cant get it to work, and im farely good at game python

(Carl) #4

this one is tricky I fooled around with it for a while and the problem seems to be that setObject() doesn’t want to work as intended…BUT:

adder = con.getActuator('adder')


eval executes the compiled code between the brackets (’) string and single are just a couple of needed arguments

play with this and it should work, oh and dont forget


(I actually forgot why I did it this way…hmmm)

Have fun!


(saluk) #5

I got it to work easy, so you might be having trouble with the actuator. How are you getting it and what is your error?

You might not be getting the actuator correctly.

Make sure the actuator is connected to the python controller.

In the python script, make sure this is at the top:

c = GameLogic.getCUrrentController()
adder = c.getActuators()[0]  #Gets the first actuator added to the python controller

If you are in 225, 225 might have problems, from what I’ve seen it has a lot of bugs. I didn’t need to use eval in mine, but you might need to do that in 225.

(lizard809) #6

i tried both methods, niether worked then i tried:

print act.getObject()

this crashed blender so i restarted the computer, tried saluks method again, just for fun, and it WORKED. i didn’t do anything different so im very frustrated.

thanks for the help saluk and Carl, I’ll let you know if i get this working in the game im working on

(Rob) #7

Not sure as I haven’t tried this but sometimes the object seems to need to be defined as an actor and also activating true pulse mode can help I think.


(saluk) #8

Well, mine didn’t need to be defined as an actor, but trying to get python to work in blender is sometimes very buggy and annoying. ESPECIALLY if you are using 225. Anyway, glad I could help.

(lizard809) #9

ok, i figured out what was wrong, the python that had setObject was an overlay scene but the actuator was on the other active scene, and the python couldnt find the object that i wanted to add because it wasnt on the overlay scene. when i linked it to the overlay scene then it would add the object but it was added on the overlay scene even though the object with the actuator is on the other active scene. so i guess ill have to find another way around this problem.