Variable with a constant value

I try to create a variable and then change the value in the gameplay, but that variable becomes constant and I can’t change it, I can’t use properties anyway (I already have a lot).
Example:

import bge
my_variable = 0.0
if any thing:
    my_variable += 0.1

first, are you in module mode?
second, use global my_variable in functions to access the variable.
third, looks like theres a missing underscore :wink:

Ok, i fixed haha. I can modify this value like this?

I not using a module, only a condition.

As far as I’m aware, Python doesn’t support static variables. If you put a print statement after your += 0.1 then you’ll find the variable has changed.

If that runs every frame, then it’ll always start at that value. It’s common to have a startup script that initialises variables in a global scope.

If you want to keep using something in your blend where ever you need it then you should use a globalDict to store those variables, you can even save and load it when it’s in the dict.

from bge import logic

GD = logic.globalDict

GD['some_variable'] = 100

hundred = GD['some_variable']

to save and load it use the logic bricks

Thansk again guys, yous helped me so much!