1
$\begingroup$

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.

$\endgroup$

1 Answer 1

0
$\begingroup$

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

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

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

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .