Problem Scoring in Game Engine

I have Blender 2.42.
I am trying to make a game.
I am using the “Scene Overlay” Feature to display the score.
There is a problem sending messages.
The message is “Add2points”.
In the other scene is a plane with bitmap text and the appropriate properties.
When it recieves the message “Add2points” it is instructed to add 2 points to the respective property.
It adds 4.
If I tell it to add 1…
It adds 2.
I suppose I could work around this, but what if I wanted to add 1 point?
This problen even occurs in the games included in the blender gamekit when I run them in 2.42.
If I run them in Blender 2.24, there is no problem.

Could someone please explain why this happens and how to avoid it?

Sounds like a glitch that has to do with the sensor triggering twice, once when the message arrives and once when it stops arriving.

Try changing the “f” value in the sensor and see how it works.

If that does not work, you could try a py script:

Add an integer property to your scoreboard, name it “pulse” (no quotes). Logic Brick setup: Message–>PyScript

cont = GameLogic.getCurrentController()
own = cont.getOwner()
 
#Keep track of pulse passes.
own.pulse += 1
 
if own.pulse == 2:
    #increment your scoreboard here, IE:
    own.scoreboard += 2 #Add 2 points.
    own.pulse = 0 #Reset pulse tracker.

I didn’t test this, but I think it should work. Hope it helps.

It is fine in 2.41

I think it’s because the message sensor is sending two positive pulses instead of one positive and one negative. The way I got around this was in python. If you give the message a body, only one of the pulses will contain the body. So you can use :


if message.getBodies():
     do something

This will cause only one do something, whereas


if message.isPositive():
   do something

will cause two do somethings

Thanks, I will try all of these things and I’ll tell you whether they worked or not.

This is a known bug in 2.42. As fireside said, the message sensor is sending two pulses instead of one. Monster is right, it worked fine in 2.41, but I think something got mixed up when the bullet physics system got implemented.

Here’s a good solution for your problem. Create a global variable to store the score. (Globals are variables that you assign to the GameLogic module.)

GameLogic.score = 0

Run the code once on start up using an Always sensor with True Pulse Mode turned off (the default is on, since without true pulse mode it doesn’t run always, only once). Then whenever you want to increment the score use a Python script instead of the message sensor.

GameLogic.score += points

Then you just need to read score in to your display.

Actually, now that I think about it you might be able to use an Expression controller instead of running Python scripts, since what you need to do is so basic. Try “Always (true pulse off) --> Expr: GameLogic.score = 0” to initialize the variable, then “Score Event (whatever it is) --> Expr: GameLogic.score += points”. I’m curious, so I’ll give it a try and see if it works.