Add object possible?

I’m attempting to add an object twice with one add object actuator. Then define each individually, all well and good so far I add one, name it,
(actu.getLastCreatedObject().name = name)
but i now want thier initial velocity set independently. Ideally using just the add object actuator. Alternatively I could add a motion actuator but then I can’t seem to get the spawned object, I assume because it is not in the object list from the start. Does anyone have any ideas how to solve this.

Just to clarify I have one object I wish to spawn twice and then give a different velocity to each one.

Use a script and import GameLogic as g.
create a global variable (g.number)
when the object is created have it add 1 to the variable
based on the value of the variable, change the speed.
You can also add the variable to the obj speed. (but make sure it only adds once or edit a property on the object to make it the one that speeds up.)

That might give you an idea.

Mmmmmm, I’m not sure I’m getting you here. My script allready adds the object and auto asigns a name and number. So I can have as many objects spawn with distinct names as I like.
I now want a way of applying a velocity to them. I think I’m gonna post my script thus far, it’s eventual aim is to provide a path finding solution whereby it checks with rays whether a path straight to the goal is available. If the ray is obstructed by an object then two empties spawn at the object site and move in oppisite directions perpendicular to the ray until there ray hits either the end or an object other than themselves. Rinse and repeat ad infinitum until the goal is hit by a ray. Then path lengths are compared by a sort of Djikstras algorithm (finished by the way).
I appreciate this may not be a good pathfinding solution but I figured it would serve okay in an outside situation or could be adapted for a cover and advance system. Really I just fancied trying to write a script from scratch without copying another idea.

g = GameLogic
cont = g.getCurrentController()
own = cont.getOwner()
objList = g.getCurrentScene().getObjectList()

# Variables and lists
if not hasattr(GameLogic,"variable"):
    GameLogic.variable = 0

#Get Obj
# goal and self are start and finish points,
#  empty is spawned as an intermittant point.
Empty = objList["OBEmpty"]
goal = objList["OBGoal"]
self = objList["OBCube"]

# ray to goal from self
ray = own.rayCast(goal, self,0, "Obsticle")

#Actuators, would like to use one add
actu = cont.getActuator('add')

# Objects to add, only one

# get object Normal
normal = ray[2]

# add objects, assign names
if normal != None:
    variable = GameLogic.variable
    last = actu.getLastCreatedObject()
    name = "empty" + str(variable) = name
    #may be unneccessary was for use in Djiskras
    objName =
    variable += 1
    name = "empty" + str(variable) = name
    # may be unneccessary was for use in Djiskras
    objName1 =
    variable += 1
    Xforce = normal[0]*2
    Yforce = normal[1]*2
# not working
    if Yforce <= 0:
        if Xforce >= 0:
            objName.setLinearVelocity(-Xforce, Yforce, 0)
            ObjName1.setLinearVelocity(Xforce, -Yforce, 0)
            objName.setLinearVelocity(Xforce, -Yforce, 0)
            objName1.setLinearVelocity(-Xforce, Yforce, 0)
        if Xforce >= 0:
            objName.setLinearVelocity(Xforce, -Yforce, 0)
            objName1.setLinearVelocity(-Xforce, Yforce, 0)
            objName.setLinearVelocity(-Xforce, Yforce, 0)
            objName1.setLinearVelocity(-Xforce, -Yforce, 0)
g.addActiveActuator(actu, False)

p.s. I know there are parts my script doesn’t do yet but one problem at a time eh.
Once again thanks to all who take the time to help out a humble python noob.

Shameless bump!

Its not working because you are trying to get the velocity from the name, instead use the last variable. You will probably have to rename the second last variable last1.

Also, in 2.5 renaming of objects in runtime will be depreciated.

Then how will we rename objects. I need to rename my objects just to make them different and avoid errors.

Thanks andrew that was the kind of answer I needed.

renaming objects could be supported, however it was only partly working in 2.48 (some lookup tables were not updated)
It would also mess up because objects are expected to have an OB prefix and you could remove this manually.

Id like to see an example where hash(ob) isnt enough to get a unique value.

The main thing it cant do is get the object based on the hash… but not sure how to add this in a pretty way.
ob= sce.getObjectFromHash(id) ? :confused:

if the BGE’s clist didnt alredy have index lookups we could do…

ob= sce.objects[id]

But id is a number… so there is no type for this…

ob= sce.objects[None, id]
ob= sce.objects[“ID”, id]
ob= sce.objects[float(id)]
ob= sce.objects[[id]]
ob= sce.objects.from_id(id)
ob= sce.objects[GameLogic.HashInt(id)]
ob= sce.objects[complex(id)]

would all work but are ugly

I have two characters that are the same spawn at different points on the map and run around fighting each other. I rename one player and the other enemy using python and change their player property to 0 for the enemy, and 1 for the player. If object renaming is removed, it might break my battle system.

Sorry, hijacking this thread. KTHXBAI.

re-Hijacking. Anyone any ideas why my spawned object should be much bigger than the object being copied. I think Blenders glitching. Stupid vista!!!
No worries solved it somehow everything was scaled up loads and it made the spawned object come out larger than it should fixed now though.

# The usual
import GameLogic as gl
con = gl.getCurrentController()
own = con.getOwner()

# The add object actuator
add = con.getActuator("add")

# this will create the gl.myObjs list that will
# allow you to access your objects at any time globally
if not hasattr(gl, "myObjs"):
    gl.myObjs = []

# Setting up object one
add.setObject("object") # the object's name you want to add
add.setLinearVelocity([0.0, 0.0, 0.0]) # this is your starting velocity
# Adding your object
add.instantAddObject() # an amazingly convenient method
newObj = add.getLastCreatedObject()
gl.myObjs.append(newObj) # saving the object pointer for future access

# Setting up object two (same process as before)
add.setLinearVelocity([0.0, 0.0, 0.0]) # this is your starting velocity
# Adding your object
newObj = add.getLastCreatedObject()

# So now your objects can be accessed from the gl.myObjs list anytime,
# but don't forget to remove your objects from the list when you're done
# like this or something:
# obj.endObject()
# gl.myObjs.remove(obj)

I use = “new name” to rename my objects. Will I still be able to do that in 2.5?