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


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:


But i dont know how tu use this:


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.

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

Source (i own the script): http://blenderartists.org/forum/showthread.php?381505-FR-EN-Advanced-Moving-Script-for-the-BGE-V2-0

  • $\begingroup$ 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). $\endgroup$
    – elmo
    Sep 18 '15 at 12:28
  • $\begingroup$ Your code replace this exactly? if "VitesseMarche" not in own: own["VitesseMarche"] = 0.2 $\endgroup$
    – Hack0re
    Sep 18 '15 at 12:39

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.