set property value via python

How can I set a property value using python? I’ve been tring a lot of methods (SetValue, act.value) without succeding.

Something more, I want to set the message subjects as property value.

Read the documentation. But in answer to your question.
con = GameLogic.getCurrentController()
yourObject = con.owner
yourObject[“propertyName”] = whatever you want to set it to.
You need to have defined the property outside of the game engine.

cont = GameLogic.getCurrentController()
obj = cont.owner

sen = cont.sensors[“input”]
subject= sen.getSubject()

act = cont.actuators[“output”]
act.propName = “prop”
act.value = subject

Why is this not functioning? I’m actually tring to set the mess subject as property value.

Even this doesn’t funtion

cont = GameLogic.getCurrentController()
obj = cont.owner

sen = cont.sensors[“input”]
subject= sen.getSubject()

obj[“prop”] = value

The message actuators are actually really annoying to work with. instead i usually use, well in your case, obj.sendMessage(Subject,body,to) The last two arguments are completely optional.

mmm, but in this case i don’t need to send a message from this obj, but to transform the subject of the received ones into property values

Maybe obj[“subject”]=sen.subjects[0] ?



What is the meaning of the [0]?

It means that value of KX_NetworkMessageSensor.subjects instance variable is list of strings and not just string.

the message sensor can receive more than one message at a logic tick. With subjects and bodies you get a list of all messages. From the lists you can retireve the messages you are interested in.
Be aware that the messages are thrown away after that logic tick.


If you want to print all subjects to console:

print "Subjects received",
for subject in sen.subjects[:]:
    print subject,

So, assuming the sensor recieve more than a message per tic, which of them will it pass? The first or the last? Or the n position setted by [0] o[n] ?

I don’t want to print all. My aim was only this to set the recieved message as the property value, for an rpg game

subjects is an array. subjects[0] accesses the first item in the array.

What order the messages are stored in the array, does not appear to be specified in the documentation.

However, it could be reasonable to assume that 0 would be the first recieved, 1 the second, and so on.

Thanks very much to you all.

Are these the best Api references? Do you know others?