hello all, im trying to create a class, a simple one, im working on class from few days so im a little bit noob but anyway, the problem is that i want to add this object with related python code trought an empty, when i add the first object he gets all the right things i have inizialized in the class but when i add the second one the script seems to reinizialize the first one.
for example in the init method i put a variable gets a random number and when i add the first cube the property works giving me always a random number (for the first one object).
when i add the second one the code reinizialize the first one and the second one seems not to be an object class.
i think the problem is in the name of the mesh. i tried with id and other things but seems dont want to works.
i think the solution its to rename all the object i add and give them the class afther i call them via addobject method but dont know how.
can someone help me pls?
i think you will laugh looking at this code because i know its orrible but im new on propramming code language
here is the code i have created:
import bge import random cont = bge.logic.getCurrentController() own=cont.owner scene=bge.logic.getCurrentScene() ob=scene.objects class test: hp=int() def __init__ (self,nome): self.hp=random.randint(1,100) self.nome=nome self.scene=bge.logic.getCurrentScene() self.ob=self.scene.objects[self.nome] self.ob["hp"]=self.hp def adda(): cont = bge.logic.getCurrentController() own=cont.owner empt=scene.objects["Empty"] adda=own.sensors["adda"] cub=scene.objectsInactive["Cube"] if adda.positive: scene.addObject(cub,empt,0) cub=scene.objects["Cube"] cub=test("Cube")