adding and ending objects with python

Why does not this add object from another layer?


import bge
scene = bge.logic.getCurrentScene()
obj = scene.objects

list = [obj['Cube1'], obj['Cab'], obj['Cube3']]
for o in list:
    o.endObject()
    
    
    last = [obj['tringle'], obj['weird sphere'], obj['shatter tringle']]
    for o in last:
        o.addObject()

Objects are added by name string.


scene.addObject("triangle", obj_that_adds, time)

addObject has the following properties: object, other, time

Object identifies the object being added (string)
Other identifies the object being used to add the Object (string)
Time identifies the lifetime (in frames) of the object being added (integer)

So



import bge
scene = bge.logic.getCurrentScene()
cont = bge.logic.getCurrentController()
own = cont.owner
obj = scene.objects


list = [obj['Cube1'], obj['Cab'], obj['Cube3']]
for o in list:
    o.endObject()
    
    
    last = ['tringle', 'weird sphere', 'shatter tringle']
    for o in last:
        scene.addObject(o, own, 0)

should work

MrPutuLips that code did not work.Here is the error.

Read new prefs: C:\Users\My world\AppData\Roaming\Blender Foundation\Blender\2.6
9\config\userpref.blend
found bundled python: C:\Program Files\Blender Foundation\Blender\2.69\python
read blend: C:\Users\My world\Desktop\game pop.blend
Detected GL_ARB_texture_env_combine
Detected GL_ARB_texture_cube_map
Detected GL_ARB_multitexture
Detected GL_ARB_shader_objects
Detected GL_ARB_vertex_shader
Detected GL_ARB_fragment_shader
Detected GL_ARB_vertex_program
Detected GL_ARB_depth_texture
Detected GL_EXT_separate_specular_color
Blender Game Engine Started
Python script error - object 'Cube1', controller 'Python':
Traceback (most recent call last):
  File "game.py", line 15, in <module>
TypeError: scene.addObject(object, other, time): KX_Scene (first argument), expe
ct a KX_GameObject or a string
Blender Game Engine Finished
 
 

Did you test it?

I didn’t test it. Sent it from my phone’s browser. I edited the code. the “last” should “o”. Now it should work… I hope :wink:

Cool thankyou very much.