Hi all, Im new at blender game, and i don’t know how use same object in different scenes. Then i make full scene copy, my python scrip stops working, and i know is because objects names. i can make new scrips with different names but its too much trouble. Can someone help me out for finding simpler solution.
import bge
def main():
cont = bge.logic.getCurrentController()
kulka = cont.owner
keyboard = bge.logic.keyboard
scene = bge.logic.getCurrentScene()
touch = cont.sensors['Touch']
hit = touch.positive
damage = 0.1
if 'active' not in kulka:
start(kulka, scene)
if hit and kulka['active'] == True:
print(touch.hitObject.name)
touch.hitObject['hp'] -= damage
kulka['active'] = False
kulka.color = (1,1,1,1)
#obstacle["hp"] = obstacle["hp"] - 0.1
When you want to use same object in the same or different scene you should duplicate it with dupligroups.
In your first scene select the object you want to duplicate -> Groups -> Add to group -> give a name
In your second scene you can find the group in Add -> Group Instance -> your name
You can name this instance whatever you want but the object in game will have identical name to the object in another scene it refers to. This way also copies any logic associated with the object.
Please use code tags when posting code snippets (advanced editing). Otherwise your code is nearly unreadable and syntactical incorrect.
You can’t use the same (game) object in different scenes. You can use equal (but not identical) objects.
Hint:
Do not refer to names if you have object references, this will produce unexpected results especially if there are other objects with the same name:
scene.addObject(“Suvis”, kulka.name, 60)
If you want to reuse code, better do not rely on object names. You can for example define the object name to be used in a property:
PsuvisName = "suvis"
'''Cofigures the name of the object used as suvis'''
...
scene.addObject( getSuvis(), kulka, 60)
...
def getSuvis():
'''Returns the game object configured as "suvis". Assumes there is only one in an inactive layer.'''
owner = getCurrentController().owner
suvisName= owner[PsuvisName]
return getCurrentScene().objectsInactive[suvisName]
This way you can have several objects each running the same code but with different properties called “suvis”.