# If property does not exist, use default value in python

I have a problem with my script, i want to let the user creating or not the property, but when the property is not used, blender give me an error (its normal). i have tried things like:

if "myprop" not in own:
own["myprop"] = MyValue


And

defaultValue = MyValue
value = own("myprop", defaultValue)


But nothing work, i allways get an error.

Maybe the second one can work, but i dont know how to use it correctly.

I have another question, my player use the Character physics, and in the physics menu, we have the Jump Force. I want to set the Jump Force in python, i know the function for doing this is:

jump_speed


But i dont know how tu use this:

GameObjectSettings(bpy_struct)


Thank you.

Extract and edited from my Movement script:

import bge

def main():

cont = bge.logic.getCurrentController()
own = cont.owner

# Verifier si les propriété existent.
Verif_Prop(own)

def Verif_Prop(own):

# Verifie si la propriété existe.
if "VitesseMarche" not in own:
# Non définie, utiliser la valeur par défaut.
own["VitesseMarche"] = 0.2


• Shorter way is own.setdefault("VitesseMarche", 0.2). Or if you don't want to modify dict where you get value you can just do own.get("VitesseMarche", 0.2). – elmo Sep 18 '15 at 12:28