python first object in list don't work

i have a project in a open world and for tree’s etc i script this code

import bgefrom bge import logic


cont = bge.logic.getCurrentController()
own = cont.owner
obj=logic.getCurrentScene().objects
scene = bge.logic.getCurrentScene()
spawn = cont.actuators["Spawn"]


Near = cont.sensors["Near"]
near_obj = cont.sensors["near_obj"]






colObjectList = Near.hitObjectList #create the list--


for i,object in enumerate(colObjectList):
    for x in colObjectList:
        listOb = id(x)
        listObject = obj.from_id(listOb)
        
        if'logic' in listObject:
            colObject = listObject 
            controller = listObject.controllers
            own.worldPosition= colObject.worldPosition
            if not near_obj.positive:
                for i,controller in enumerate(controller):
                    print (obj)
                    spawn.object= str(controller)
                    cont.activate(spawn)

the problem is that the first object he see with logic inside spawns’ a tree,
but by the second object no tree.
what do i wrong?
sorry about my bad english

Hey Gamad!

Could you explain a bit more precise what you want to achieve with your script or even better append a blend file?
I am having problems interpreting your code that way :wink:

the achieve for the script is that he load objects from another layer into this layer.
the way:

  1. search he for al the objects that Near the near.actuator
  2. the script check if the object(s) have a property named logic
  3. he get the worldpostion of the object
  4. look if there is already a object (near_obj) (that he stop with adding objects if there are already a object)
    5)the name of the controller from the object is also the name of a object in another layer so he set that as object from a “edit object -> add object -> add object=the name of the controller”
  5. spawn object

uploaden didnt work so maybe later but now i hope this explains a lot

It looks like you’re using an actuator to add the objects. The problem is that actuators can only be activated once per frame. Since your script runs in one frame, it can only add one object even if you call cont.activate(spawn) many times. Just use the addObject method instead.

You can use instantAddObject for this purpose I believe

Sent from my Nexus 5 using Tapatalk

yeah

for items in list:
Object = scene.addObject(object,AddLocationObject,duration)

then when spawned you can set things like

Object[‘Property’]=“something”

handy for saving and storing objectID’s etc

(what is the difference with instant vs add? skips to front of logic ?)

When I’m home I shall try Thx everyone

bad news it didnt work if you look the video you see that both trees spawn but if the right tree spawn first the left tree spawn never.
and by the objects it works well i get 5 trees on 1 place. (I saw previously with print (scene.objects)
(tree root is normal)

it always adds to the location of the spawner,

2 options,

add item then move

move spawner then add