Init ID script help

Hey everyone, I am wanting to use this script from Yo Frankie.

import GameLogic
def main(cont):

Give the sheep a unique ID

ID = GameLogic.ID = GameLogic.ID + 1
ID = GameLogic.ID = 0

own = cont.owner

For respawning.

own[‘x_orig’], own[‘y_orig’], own[‘z_orig’] = own.worldPosition
own[‘id’] = ID

print “setting ID”, ID

Warning!!! This only works when inside dupliGroups

since objects in hidden layers will still show up as a sensor.

Assign dummy value

own[‘own_rig’] = 0
for ob in own.children:
name =[2:]

if ‘rig_ram’ in name:
own[‘type’] = ‘ram’
del own[‘carried’], own[‘projectile’], own[‘kickable’]
elif ‘rig_sheep’ in name:
own[‘type’] = ‘shp’
elif ‘rig_rat’ in name:
own[‘type’] = ‘rat’
#del own.carried

Theres an an odd bug with flawsh_death object adder

set the object by name and it should help

This should not be needed

actu = cont.actuators[‘create_poof’]
actu.object = ‘flash_death’


But, there are a couple problems, I know almost nothing about Python, and I want to get rid of all the unnecasary stuff in the script that only deals with Yo frankie in particular. All I really want this script to do is give the people added their own ID, that way when I fight one I’m not killing them all.

But another problem I am faced with, I don’t know how to send a message that he recieved damaged, and have the ID comunicate that it was only him, does anyone know a good logic setup that would make it to where I
2)message sent saying he was attacked.
3)only character I am attacking recieves damage.
I know, that seems kinda deep, but I hope someone will be able to help me out with this.

I had the same problem also with the unique ID. Then I made my own script which great for enemies. Perhaps you can use it.

Here’s the link:

Otherwise, you need to give each an unique ID:

# Give each a unique ID
                        ID = GameLogic.ID = GameLogic.ID + 1
                        ID = GameLogic.ID = 0

Hope that helps a bit

Each Python object already has an unique id. You get it with:

id = id(object)


print, id(cont.owner)

why use id’s? can’t you use the object name?

not when you have dublicated groups objects. The names are all the same.

Dependent on what you want to achive, it is usually the best to work with references rather than ID’s.

obj = raysensor.hitObject

It does not matter if other objects with the same name exist, obj is unique. Since 2.49 you can store the reference in a property:

own[“rayedObject”] = raysensor.hitObject

What you can’t do is send a reference as message, because messages accept strings only.
You can’t keep references after the object died (endObject/endScene/endGame). Which means you can’t save it to file (you can but is worthless).

But you can store object references in dictionaries, lists, other objects, attributes, parameters etc.

usually you fight only with one. The question you need to answer by yourself is:

Which enemy am I’m fighting?

this answers all your other questions:

Messages are not a good choice for such things.

Here are some examples how to answer your question:
You are fighting agains enemies that :

  • are near you
  • collide with an object (sword?)
  • hit by a ray

The sensors provide you with the necessary object references see the API.
Unfortunatelly you need Python to use this information.