How to add stats to a overlay (Request)

How can i send information to a text on a overlay screen.
Let`s say i have a timer, it sends to a overlay the time you died
or how many times you killed something etc.

How can i send that to a text. I know i can setup the message system
When i kill A - sends message to a integer to add 1.
It`s just getting that to send to a text and change the number.


Either way, you will need to use Python to do this properly. I suggest that you use Python to access the overlay scene. From there, you can access the scene objects from your main control logic, and set the relevant properties.

if 'overlay' not in own:
    for scene in bge.logic.getSceneList():
        if scene.name=="overlaySceneName"
            own['overlay']=scene
            own['overlayText'] =scene.objects['textObjectName']

own['overlayText'].text="whateva"

I suggest to use an MVC architecture on your implementation.

The Model is the part that keeps the “stats”. This can be anything. A property of a game object, a Python data structure or whatever.

The View is the part that shows the status of the model to the user. In your case the Text object. It can be a bar, a slider or a animated mesh. It can even be … nothing (no information is information too ;)). Either way the View can be multiple objects.

The Controller (not the controller brick ;)). Deals with input, e.g. changes to a slider, keyboard input … anything that interacts with the model.

Typically the model does not know about view and controller. It can live without them.

The view knows the model and operates on changes of the model to show the respective status. A view can show the status of the complete model, or parts of it. There can be several views to the same model/value. The model should not care how many views are present. The view does not know the controllers. As it shows the state ofthe model, there is no need to know about controllers.

The controller processes input to the model. This means it triggers triggers operations on the model and updates the views. Typically a controller has a close relation ship to a specific view and the model.

I guess … too much theory.

How to apply to your situation. As you do not want input (yet) we can skip the controller part and focus on model and view.

Unfortunatelly you did not tell where “information” is coming from. So I assume you have an object “Model” with property “death time” and “kills”, The view is a bunch of text objects with some fancy graphics around it.

Basically you already have an implementation:

Whenever the property “death time” changes you send a message “death time changed” to the view. As the model does not know the view(s). So you do not send the message t oa specific target. The interested views can simply listen to the message “death time changed” to get notified for update.

Now there are multiple options:

  • You send the new value within the message body. This way the view can extract it from there. This is fine on string values or values that can easily be converted to and from stings (as the message body is string). Due to the dynamic nature you need Python to read the body.

  • Treat the message as notification and let the view access the model to get the according values. Typically you need Python to read the model (e.g. the property value from model object).

There are more options, even without Python. Typically they are based on some assumption (e.g. one message = one increment; one message per frame only).

You can read about using messages in

Maybe it helps

Edit: I forgot to mention that using a model makes it extremely easy to save it to a file.

You can use python to copy properties between scenes. Perhaps an empty or empties, on the main scene that holds the properties, then on the HUD or overlay, Text that copies the property from that empty, or whatever. I used a script found in resources that works well. Or write your own.

I’ve made a small blender “game” to demonstrate how I did it, should be fairly self explanatory. If you have any questions, let me know!
https://www.sendspace.com/file/g1xb3r