The mess property never updates itself, so the propC always stays the same as the very first item that was collected. Does anyone know of a way to update this before the message bodies are checked by the main function?
You ask a similar thing in your other thread. As written, I do not know why you want to set propName.
propName is the attribute that defines the property name of the actuator. This is equal to writing a value into the “property” field in the GUI.
I have the impression, you want to change the value of the already set property. To do that (with a property actuator indeed) Write the value as string into the “value” attribute: bge.types.SCA_PropertyActuator.value.
As mentioned in the other thread, if you want to get the name of the hit object write its name into this attribute and activate the acutator.
def hitObjectNameToValue(controller):
hitObject = controller.sensors[0].hitObject
if not hitObject:
return
actuator = controller.actuators[0]
actuator.value = hitObject.name
controller.activate(actuator)
The API does not support that. The PropertyActuator and the PropertySensor both have an incomplete API. This usually does not matter that much as you can set properties without the actuator. But you have to give away the option to configure other parameters via GUI (such as configuring the property name).
@Joystik Studios: Unfortunately I do not understand what you want to do with this code. The choice of variable and function names doe not let me guess what they are supposed to do or contain. Can you describe what should happen when (maybe with a why)?
The python script is to determine the body of the most recent message received and put that into the property that the Property actuator changes. Does that make sense?
But there are some things to explain a little further:
How you define that? The messages come in without a specific order. Your idea of processing the last message has the same correctness as my version using the fist message.
Be aware a property consists of a name and a value. If you put a value into a property it means you write it into the value. You identify the property by its name.
If you look at the Property actuator you see there is a Name field (labeled “Property”; attribute propName) and a Value field (named Value; value attribute. If you want to set the value you write the new value into the value field and activate the actuator. hen activated the property actuator it will identify the property of its owner with the given name. If the actuator is in assign mode it writes whatever value is in the value field into the found property. Be aware the value field will be interpreted. If you want to assign a string you need to enter “string” including the ".
That’s what I mean, the message body is the property name. The most recent message received should go like this:
Player collects a ball. ‘Ball’ is now the most recent message body, and the script adds 1 to the property ‘Ball’. All the messages have the same subject.
Player collects a cube. ‘Cube’ is now the most recent message body, and the script adds 1 to the property ‘Cube’.
Player collects a ball again. ‘Ball’ is now the most recent message body, and the script adds 1 to the property ‘Cube’.
That is how I want it to work, using one property actuator and one message sensor.
The property that the actuator changes must be dynamically allocated by the python script based upon the body of the message that was last received, lowering the amount of logic bricks and simplifying the system. Also I don’t understand the code you gave me, BluePrintRandom. I am setting the property with python, but trying to keep the amount of properties and bricks at a minimum.
But these properties are most likely going to be accessed by another script. There is probably a solution for this but it’s not what I want.
Also that does not solve my problem that the message.bodies[0] never updates. This is the only thing that I need fixed.
I wonder why you want to send property names around. It looks like you want to send categorized information.
Due to the dynamic characteristics of an inventory it makes sense to implement in Python.
Just now you communicate via messages, but it looks like you are skipping messages (you deal with the first message only).
You shoud think about how your inventory should work. This means where to store the inventory content, ho to put additional content, how to get content from the inventory etc.
import bge
def main():
cont = bge.logic.getCurrentController()
own = cont.owner
message = cont.sensors['Message']
if message.positive:
for items in message.bodies:
if items=="Test": own['Counter']=own['Counter']+1
if items=="Test2": own['Counter']=own['Counter']+10
main()