I run into this problem often. I want to alter a variable in a script, but if I don’t define the variable first I get an error, and if I do define the variable, the variable gets reset to what I define it to be every time the script runs. I’ve been using either global variables or properties to get around this problem, but that feels messy and incorrect for some things. I’ve tried using the “try-except” thing, but I can’t seem to get that to ever work properly. is there a way to make something only happen once in a script even if the script is triggered more than once, or is there a way to define variables once without using global variables or properties.
import bge cont = bge.logic.getCurrentController() own = cont.owner lmc = cont.sensors["lmc"] #left mouse click a = 1 if lmc.positive: print (a) a += 1
I want it to count up every time I left-click
what I want:
while this is just a very simple example, it would greatly simplify some of what I am working on.