track to bolean true

hi all.
i am making my small game, and i need some help.
i would like to make my character follow an enemy,
every enemy has got a bolean property set to false,
and i can turn it to True by clicking on him,
my character should follow only the enemy with the bolean property set to True.

and also two enemy cannot have the bolean property set to True at the same time so, how could i make all other enemies property be set to false when i click on a particular enemy?

Logic bricks
MouseOverAny(‘Enemy’)-----------Python controller(Pickem)
LeftMouse------------------------------/

Dependencies - > must have property Enemy in enemy units.

Pickem -Python script


import bge
cont = bge.logic.getCurrentController()
own = cont.owner
MouseOverAny=cont.sensors['MouseOverAny']
LeftClick=cont.sensors['LeftMouse']

if MouseOverAny.positive and LeftClick.positive:
    # MouseOverAny.hitObject = the unit you clicked
    MouseOverAny['Property']=True
    for objects in bge.logic.getCurrentScene().objects:
        if 'Enemy' in objects and objects!=MouseOverAny.hitObject:
            objects['Property']=False
                 

However, it would probably be more flexible to set a single units property to the target,
and then have the unit move his own navigation target to the enemy,

import bge
cont = bge.logic.getCurrentController()
TargetingModule = cont.owner
if 'Actors' not in own:
    ActList = []
    for obj in scene.objects:
        if 'Actor' in obj:
            ActList.append(obj)
    own['Actors']= ActList
else:
    index=0
    for actor in own['Actors']:
       if not actor.invalid:
           if 'NavTarget' not in actor:
               for child in actor.children:
                   if 'navTag' in child:
                       actor['NavTarget']=child
                       actor['Target']="Empty"
                       child.removeParent()
                  else:
                      if type(actor['Target']) is not str:
                           if not actor['Target].invalid:
                                 actor['NavTarget'].worldPosition=actor['Target'].worldPosition
                            else:
                                actor['Target']="Empty"
             index+=1
   
      else:
            own['Actors'].pop(index)

this code looks up a property Target, in each actor, if its a game object, it sets the actors navigation target object to the targets worldPosition

Typed it out on a phone, so it will need ran/deugged

thank you for the quick reply @BluePrintRandom
i tried both of your script but none seems to work.
i post a simplified scene to allow you to give me further assistance.

move your cursor above the enemy (red cube) an press ‘T’ to toggle
the ‘Target’ property.

in a scene with multiple enemies, i would like my player to seek,
usin the ‘steering actuator’, only the latest enemy whose
‘Target’ property has been toggled to 'True

i’d prefer to use the steering actuator because it allows me to use also a navigation mesh.

so basically i need a script that make a list of the objects in the scene with the property ‘Enemy’,

then chose the last one whose property ‘Target’ has been toggled to ‘True’
(to achieve that the script can automatically turn to False the ‘Target’ property of all the ‘Enemy’ except the one that you target)

and finally set that enemy as target for the steering actuator.

i know i ask a lot. but i’m not good at python, i really need help.

game.blend (461 KB)

Left mouse while aiming at a friendly = select friendly unit

Left mouse + CTRL while aiming at friendly = add unit to list

Left mouse while aiming at map = send unit there

Left mouse while aiming at enemy = set selected units target to enemy

Design choices -> I used a manager that sets where the navTarget should go, so that you don’t have to parent the navtag to a enemy unit, because deleting the enemy unit would then also delete the navtag :smiley:

Attachments

BGERtsGutsVersion12.blend (518 KB)

thanks again BluePrintRandom

i saw your video and it’s pretty much what i want to achieve, but i found another way to do it.
searching around the forum i found this script

import bge



def main():


    cont = bge.logic.getCurrentController()
    scene = bge.logic.getCurrentScene()
    own = cont.owner
    


    
    seek = cont.actuators['Steering']
    
    trackTo = [ob for ob in scene.objects if ob.get('Target')]
    
    for p in trackTo:
        print(trackTo[0])
        
    ##seek.target = "trackTo[0]"

‘trackTo’ is the list of enemy i need to set the target for the steering actuator.
the problem is that i don’t know how to dynamically change the target of the steering actuator

this is the error that i get

ValueError: actuator.object = value: KX_SteeringActuator, requested name “trackTo[0]” did not match any KX_GameObject in this scene

how can i set the target ?

ok, I would get the file I uploaded, and take a look at it

a trackTo is a actuator, and is not the steering actuator,

calling cont.actuators[‘TheNameOfAActuator’] will work if it is linked to the python controller running you script

sensor-------python control--------your actuator

the file is there for you do dissect / ask questions about

I commented out the code, but not the very basic stuff

take a look at ‘GameLogic simple’ in templates in the text editor

own[‘Property’] = a property (just like in the logic editor properties)

Manipulating the property
unit[‘Target’] will set your target, however some care is to be taken, as the object may be deleted (the actor dies?)

edit:
Continued

if you are calling steering and telling it to track a object that does not exist anymore, then you will
throw a error and if you throw enough, it simply shuts your script off,

I deal with most of these cases in the script I posted in the blend I uploaded,

I split it into 3 scripts

pick actor list

pick target for all objects on list

and move actor NavTarget to enemy unit,

if the enemy unit dies, the NavTarget does not.

ok blueprintrandom, i think i got it. thanks for the help.
i’m going to study your scripts an try to adapt them to my game.

ok this is what i came up with, using your blend as an example

untitled.blend (606 KB)

i used mostly logic brick, there is only a small script attached to the green cube that sets the cube position
it work exactily as you RTS selector without the need to create any list.

thank you again for your help.

ps: do you know how to mark this thread as solved?

ok ok. this work just for static enemies. if they move everithing brake into a lot of little pieces.
i need a list

No, the target update system should move the nav target each frame,

Care to drop the file your having issue with?

Are you enemy units marked with the property ‘Enemy’ ?