Assign Property Value with Message Body I'm looking for a way to have object 1 assign a random value to property "Gold". If the property value turns out to be higher than 10, I have a Property Sensor to check for that, and if it's true, it will activate a Message Actuator with the subject "Add Gold" and the property "Gold" as the body type (Not text). 

In my head, this will embed the property "Gold" into the message "Add Gold" that is being send out to other objects.

Now, in object 2, I have a Message Sensor that looks for a message called "Add Gold". This is then connected to a Property Actuator which will add the message to the property "Total Gold". 

The problem here is that this does not seem to work, and I'm not sure what I'm doing wrong. 

Object 1 logic that will embed the value "Gold" to a message and send it to Object 2.


Object 2 logic that will look for added gold message, and add the value in the message body to it's property "Total Gold".


I have the information sent to a Game Controller (Empty object) which handles all important global information so far. On my HUD screen, I have a counter working as a total resources counter, which includes among others, the gold values I want to send. The HUD counter then copies the property value "Total Gold" from the game controller, but nothing appear on the HUD (The counter starts, and stays at a -1 value, even after picking up the resource boxes (the grey ones being dropped by the yellow cubes)
I have done a simple test and it did  not work without a value to add to the property. You need to have your logic like this:


The script only activates the actuator "Message", which send the message.

logic.getCurrentController().activate(logic.getCurrentController().actuators['Message'])


And if you dont set a value e.g "15" to add on the property actuator it will not work. You can't do ( + 0 = ?).



EDIT

I failed to make the random actuator work, but it's very easy with python.

For the mineral object: (You may already done this!).
1. Make a proterty call mineral
2. Add a collision sensor(True level triggering) with property player &lt; and > edit object actuator - end object.

 

For the player object:


Make a proterty call player
Add an always sensor an a python controller
Add a collision sensor(True level triggering) with property mineral to the python controller




Script:

#import needed libraries
from bge import logic
import random

#main function or module.
def main(controller):
    # Param controller = bge.logic.getCurrentController
    #eval if collision sensor activated
    if controller.sensors['Collision'].positive:

        # Gold attr = gold attr  + Random num
        controller.owner['gold'] += random.randint(10, 50)
    print(controller.owner['gold'])


#Game update######################## every frame if always sensor true level triggering

#call function        
main(logic.getCurrentController())




EDIT

to send the message use:

controller.owner.sendMessage('subject', body = str(controller.owner['gold']), to = 'object' )


and retrive it:

if logic.getCurrentController().sensors["Message"].positive:
    gold = logic.getCurrentController().sensors["Message"].bodies[0]


Api sendMessage

Api messageSensor.bodies