Python modify property actuator

I am trying to use python to reassign the value a property actuator sends out. The program works fine, besides not reassigning the new value. I move around the “cont.activate(camname)” line to confirm that the line works everywhere besides directly after the “camname.setproperty(“cam1”)” line. Please help if you can. Thanks. I have blender v. 2.6.3 and I have am using a string type property

import bge

def main():

cont = bge.logic.getCurrentController()
own = cont.owner
contzero = cont.sensors['0']
contone = cont.sensors['1']
key1 = cont.sensors['key1']
key2 = cont.sensors['key2']
key3 = cont.sensors['key3']
cam0 = cont.actuators['cam0']
cam1 = cont.actuators['cam1']
camname = cont.actuators['camname']

if contzero.positive:
    cont.activate(cam0)       
    camname.setproperty("cam1")
    cont.activate(camname)
if contone.positive:
    cont.activate(cam1)

main()

There isn’t an actuator that has a method called “setproperty”. I believe what you’re looking for is the propName property.

You also don’t have any indentation in your code. Check the console and correct any errors you have.

What code do I want to use to set the property value, instead of what I had?

When setting properties from a Python script, it’s much easier and simpler to use the object’s built in dictionary to set properties rather than using the property actuator. Just use the following code.

obj['propertyName'] = <value>

Just replace propertyName with the name of the property and <value> with whatever value you want the property to have.

So all I’m supposed to do is type:
obj[‘camname’]=<“cam1”> I tried that and its still not working. The weird thing is that it won’t reject it, it just won’t do what I want it to. The property it is looking for is specific to the object it is attached to right? I’m sorry I’m not understanding it right away. I literally just started trying to learn BGE.

Leave off the brackets around “cam1”.

If you’ve just started using the BGE and are wanting to use Python, you should probably look up some good Python tutorials first. Write some simple programs separate from Blender until you actually know what you’re typing and why instead of just copying other people’s code.

Thanks. Yes. That’s what I’ve pretty much been doing in order to get a better understanding of the program, copying other people’s code. Do you want to point me to any good resources? I have trouble even understanding the API manual. By the way, thanks a ton for keeping with me so long.

To alter the Value field of an property actuator do this:


  myPropertyActuator.value = "new value"

this does NOT set the property, but each activation of the actuator does this.
This comes handy when using the property actuator in add mode and avoids the usage of a Python controller just for increasing a property value.

To set a property directly with the controller do what Mobious suggested in post#4. This is more useful if you use a Python controller already,

I tried using the line you suggested, Monster, with it reassigning instead of adding a string value. Instead of returning a string value, it output [“text” not found], though. Do I have to format it so it recognizes I am entering in a string?

“blah blah blah?”

I think

“a b c d”

Sorry I forgot - strings needs to be surrounded by " " as you can enter expressions as values.

so you can use:
myPropertyActuator.value = ‘"{0}"’.format(“new value”)