What is wrong with that script ???

import bge

def main():
cont = bge.logic.getCurrentController()
own = cont.owner
limit = 4

import bpy
prop = bpy.context.object.game.properties[-1]
prop.name = ‘enemy’


I want to add a property (enemy) in the game engine, but it doesnt work -.-
the test is a collision sensor who looks at the property enemy
sorry for bad english
thanks for all answers
here is the .blend2Groups one Playermodell TEST.blend (786 KB)

anyone who can help me ?

i am very frustrated with blender python api for game engine. where is the easy how to documentation? where is the walk through of simple things like adding or changing a property from python? I am searching everywhere for “how to change property from python script”

I’m having similar problems. Looking in the blender source code I can see that “game_property_new” makes a float property, and I can see the code that changes a property type from the gui, but there doesn’t seem to be any way to access that from the python API. Is anyone actually working on the python API because it seems very incomplete at the moment. PeterO

you’re in the wrong subforum, there’s a dedicated place for Game Engine since it’s not the same API at all.
it’s one of the reason I think you don’t have answers.
the second is certainly that everybody ask for the same thing about game props (as I did) although the answer is largely documented everywhere else (see GE section and http://www.tutorialsforblender3d.com/) :

import bge

cont = bge.logic.getCurrentController()
own = cont.owner
limit = 4
<b>own['ennemy'] = True</b>
# own['type'] = 'ennemy' ?
print('tagged as ennemy')

to change the prop from the object where is running to any other :

import GameLogic as g
sc = g.getCurrentScene() # maybe deprecated
#oblist = sc.objects # all the objects
noob = sc.objects['noob'] # object name or 'OBnoob' in 2.4x
noob['property'] = 'work, google, humility' # will be updated AT THE END of this script run

… then after a while and tons of bricks, look for dictionnary usage in the GE.