Create a Scoring System using python

hi again!!

This time I have a scoring system almost working that might need a little correction.

I start by setting my variables:

#This is the score we begin with (at this time)
oldScore = 0

#basicly mean that we set the score to the score+the points earned
newScore = (int(oldScore+scoreToAdd))

So to see the score I made a text object that always changes to the newScore

score.text = str(newScore)

This also works properly.

Finaly I change the oldScore to = newScore (works fine)

everything work as expected until we get this part of the script to trigger again. Than the oldScore = 0 again !

To make it clearer is here the actual code part:

if letterA:
    if pressA.positive:
        newScore = (int(oldScore+scoreAdd))
        score.text = str(newScore)
        oldScore = newScore

I think that this doesnt work as the script itself is triggered by ‘pressA’ (a keyboard sensor)
would it be better with a custom property??

Thanks again for the help on this code!

Well I’m not really into programming or anything, but i think the problem is how you are setting your oldScore variable, if i understand correctly, the script will always run from top to bottom, so say you played a game and got a newScore, when you started the script again, it would just change it back to 0. You would have to make sure that you setting oldScore = 0 happens once on the game start.

Alright so I created a custom property for my score and I can even call it through python but I get stuck there.

Maybe my brain is just to tired and its obvious but can you tell me how to modify that property through python.(add the score)

here is what I understand :

The score property in the variable oldScore.

oldScore = own.get(“zScore”)

so basicly if I say

oldScore = newScore it changes the variable but not the property :S

What I really want is zScore to = newScore

but whriting down zScore = newScore will create a variable called zScore instead of calling the property

Ah god . (1st week using blender and learning python. How long does it take to get fluent ?)

Thx again for the help btw!

well you don’t really need to use get, you could just put oldScore = own[“zScore”] i believe

yeah I just figured it out I used :

own[“zScore”] = newScore
and it works perfectly !