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
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
the achieve for the script is that he load objects from another layer into this layer.
the way:
search he for al the objects that Near the near.actuator
the script check if the object(s) have a property named logic
he get the worldpostion of the object
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”
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.
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)