Setting permanent Prop values in Python.

Ok so I want to make python to set permanent values for props in python. Here’s my code:

own.Prop = 0

if spacebar.isPositive():
own.Prop =+ 1 (or += 1)

Anyway that is fine, it adds 1 to Prop as long as spacebar is pushed, but when I release it resets to 0

yea ive had that same problem. it goes to zero because you have an own.prop = zero at the beginning if you delete that it will work.

Yea, the script is executed twice, once when you press the space bar, and once again when you release it.

So, on the first (positive) pulse, all statements are executed. On the second (negative) pulse, only the “own.Prop = 0” is executed, because “if spacebar.isPositive()” returns false on the negative pulse.

I don’t know why you need to set “own.Prop” to zero in the script. Properties have a default value of 0 as it is. So, if the default setting is your only issue, just remove “own.Prop = 0”, and it should all be fine.

PS: If you want to distinguish yourself as a programmer, do it through structure, not syntax.

Use “+=”.

That’s not a real script, that’s an example. This is how I have it setup (I have it so it can be moddable and interchangeable)

own.Item = “sword”
own.damagemelee = 23
own.damagerange = 0
own.damagemagic = 20
own.resistance = “fire”

Something like that. I can’t just make those change? Would it be better if I did:

damagemelee = own.damagemelee
damagerange = own.damagerange

and so on.

well it might work better if you set up the properties with those values in the interface… and change them using a script?

# I use this in my FDM4BGE-project
 
if hasattr (Cube, 'int') == False:
    own.Prop = 0    # reset parameter
    # and so on
    Cube.int=1
 
if spacebar.isPositive():
own.Prop =+ 1 (or += 1) 

You might not understand the little script above but its a little initialisation script, anything in the first if condition is run once.

I guess I’ll set the values in the interface. The reason they need to change is say if you use a Fire Orb on the devastation sword +1 you can now set resistance to Fire and add a few ranged points.

The problem now is, what if I want multiple resistance? Is there an easy way to add props or should I just set 4 resistant slots and set them all to “” and then add resistance?