Independent Enemys?

Ok, I need to figure out how to make enemies independent. Because right now, when I add more enemies, if one enemy sees the player, they ALL, see the player, no matter how far they are, no matter if they are looking or not.

When I created the enemy, I send messages to itself, because I thought when I added an object with the addObject function in the Edit Object actuator, all the other objects with the same name didn’t exist to the added object.

Is there a way to make each enemy independent without changing to much of the logic. Is there a script I need to use? I need help on how to figure out how to do this…

Thanks guys,


If you dont store any variables in GameLogic or other modules and keep all the settings as game props you should be ok.

Not sure whats going on with sending the message, but instead of doing this you could have a init state that does whatever startup functions are needed, then moves into the idle state (and never runs the init state again)

Are you using the logic brick to send messages or python to send it? If you are doing it through python I think you can set the receiver to a gameobject instance rather then a object name. This should solve the problem.

I’m using logic bricks, but I think what I can do is assign True/False to a property… Instead of sending a message, problem with that is that I will use up more logic bricks, saying to assign it back to false when the sensor is not true… Is there a way to do this with the same logic bricks use to assign to true? I know you can do this with python easily, but I don’t want to change the entire structure of my enemy :S. BUT, if I have to, I will, it shouldn’t take too long, but I don’t want to waste my time on something I might be able to do that will take up less time.

@Ideasman: he he he, I don’t know how init states work 0.o, that’s why I don’t use them, I still have a lot to learn with python. :slight_smile:

@Andrew101: What’s the difference between a gameobject and an object name?

Thanks for your responses guys,


If you take a look at my game’s AI, the enemies all start in an “initial” state were they do nothing except wait for the player to get close. When they get close, they move to the “chasing state” which starts them moving.

Messages are not a good way to do this at all. Messages are broadcast to everything in the current scene.

If you still haven’t figured out states, DO IT! They’re the most useful addition to logic in a LONG time.

Re: Init states, these work with logic bricks making them fairly easy to setup.

The thing is that I have a bunch or different parts to my enemy… Not just a cube, I also, know how to use states, I’m not a super noob lol. Thanks, I’ve seen your game, and my init state actually has my enemy walking forward and turning if it’s near a wall or an edge. Anyways, I guess what I’m going to have to do is select the different objects and connect them to the right controllers directly.

@Ideasman: Cool, nice to know :slight_smile:

Thanks a lot for your responces :slight_smile:


My enemy is actually quite complex… it’s not just one object. It has several empties for detection, blocks for other cubes to bounce on… etc.

There’s no reason you can’t have a nice, simple state system that works for you. You just have most of the controllers on one object… which is kind of odd, but it works pretty well.


The difference with using the object instance to the object name is when you add many enemy objects they share the same name. This is where I think your problem is, the message actuator is sending the message to the all the enemies because they all have the same name.

A game object instance is like the ‘own’ variable, or the objects in the GameLogic.getCurrentScene().objects list.

The difference with using the object instance to the object name is when you add many enemy objects they share the same name. This is where I think your problem is, the message actuator is sending the message to the all the enemies because they all have the same name.
If this is the case, you can set an init script for the enemy,which executes when the enemy object is added on the scene, where you change it’s name to “”, where i=0; i++
I think, I had a similar problem long ago with my enemies.

That could work, I’m not sure if linkxgl is using 2.49 or not. In 2.49 object names are read only.

Its best if you avoid doing a scene lookup on the object if you can help it.
How you reference another object depends on each case but if its a child you can use own.children, if there are interlinking logic bricks, you can get a sensor or actuators owner.
If there is some part of a script that deals with both objects at once you can add a reference between them (2.49 only) own.SomeOtherObject = other.

If you can keep a direct reference to the object rather then name lookups all the time this is faster and less error prone.

Ok, thanks for the responses guys,

@Sambassador: oh… 0.o, sorry, lol, I thought your enemy was a just a cube :0, my mistake, I DO have a state system. I have a script that Andrew101 gave me for the vision, but instead of returning 1, I made a property = 1 when the player is seen and 0 when it’s not. Then I have it send the result to the init state of my AI, if it gets 1, then go to the track-to state, if it gets 0, go to the patroling state, so that’s why I needed to send a message. But for some reason my ignorance and stupidity made me forget that you can connect controllers for one object to actuators in another. So that can be my solution.

@Andrew101: ahhhhh, I see now, thanks! Oh yeah, I am using 2.49, I want to get ready for 2.5 ;p

@Haidme: I’m happy to know you had the same problem, but about the script, can you explain it to me… If you don’t mind, I take long to get complex stuff in my head (eventhough that might not be as complex as I think it is)

@ Ideasman: I am using 2.49 :yes: so that will help me :slight_smile: