Locking in a select able track to target.

So for my game that I am making I need at least 2 states. A "Clickable/select able state, and a tracking state, so a players unit can track to a resource, enemy, etc. In order to do this, I am using states to separate each one. So the code I am using is this :


import GameLogic#sensors
SMouseOverAny 	= "sMouseOverAny"
SMouseLeft = "sMouseLeft"
ATrackTo	= "aTrackTo"
#check to make sure it is in fact a "resource"
def trackToResource(cont):
    sMouseOver = cont.sensors[SMouseOverAny]
    if "resource" not in sMouseOver.hitObject:
        return
    #check for sensor activation
    if not sMouseOver.positive:
        return


    sMouseLeft = cont.sensors[SMouseLeft]
    if not sMouseLeft.positive:
        return
    #activate trackto actuator with selected target
    aTrackTo = cont.actuators[ATrackTo]
    aTrackTo.target = sMouseOver.hitObject
    cont.activate(aTrackTo)

So there are 2 immediate problems I face. first of all, when I click on a person to go to an object (by changing states through mouse over and left click sensors connected to a state set actuator) and proceed to click on another “resource” they track to it, which is fine. However if i click on another guy to activate their track to function, or click on a new object, the target is updated (which I don’t exactly understand why, but I believe it has to do with how the game loop functions as I do some more research). I figured I could solve this problem by switching back to the “select able” state, which stops the update, but brings about problem #2. When the character goes back to the first state, the new target doesn’t “lock in” it reverts back to none. So I need to find a way to “lock in” the new target when it reverts back to its selectable state.
Thanks for any help .

If I understand you right:

You have several “guys” which can be in “selectable” mode or “tacking” mode.
You have several “resources” that can be detected by a mouse over any sensor.

There are two states for each guy: selectable, tracking

transitions:
selectable -> click on guy -> tracking
tracking ???

Actions
tracking: click on resource= change trackTo target

The problem you have is, that all guys are listening to the same mouse events.
A) if a guy is in tracking mode you can change the target by clicking another resource
B) if another guy goes in tracking mode it will do exactly the same

I suggest to use other states:

Idle, Selected, Tracking


transitions:
idle -> clicked on guy -> selected
selected -> clicked on resource -> tracking
tracking -> reached target -> idle
tracking -> clicked on guy -> selected

Actions:
selected: exit action => change trackTo target

I completely see what you are going for. And how I have tried to achieve that is completely isolating the tracking actuator in a third state. So then I could have idle, selected, and tracking (of course with an option to go back to selected). I modified the code above to only allow the object to go into the tracking state when the selected object is a resource. However the new problem arises that I need to get the information from what i clicked on for the object to track to to the tracking actuator without having to click again, which would defeat the point of “locking” and isolating the track to actuator so no new target can be selected.

this is simple:

in stated Selected:

when clicked a resource perform following exit action:
-> retrieve the clicked resource
-> configure the TrackToActuator with this resource
(You do that already with the above code)

The same event triggers the state change. Therefore the event: click on resource is not really the right event. This correct transition would be:
If TrackToActuator is configured -> transit to Tracking

This way it does not matter how the trackToActuator is setup (after resource click or something else like automatic finding of a resource).

Summary:
you identify the resource object in state selected + as you know the resource at that time, you can configure the actuator
if you need to know the resource object in state Tracking, you can simply see how the actuator is set up ;).

I understand what You are saying, I just don’t know howto do that

If TrackToActuator is configured -> transit to Tracking
I just don’t know how to do that without splitting the needed information (.hitobject) from the activation command. So I figured that I would remove the immediate activation from the above code at the end to avoid it reactivating the actuator. So I was going to have it activate a state actuator to send it to a third state, but I figured I had to store the .hitobject somehow and so I tried as a message, but I couldn’t get that to work. I am going to experiment with if, then commands tot try to make a barrier. But if you could explain it to me in more detail, or redirect me that would be great. Thanks.

Edit And The TrackTo actuator keeps reconfiguring itself because as you said, it keeps listening to the same mouse events So I need to figure out how to stop that.

Thank you for all the help, and I might use some stuff in the CommandPipeline, but I only glanced at it. I have successfully accomplished my goal with the added bonus of multiselection as well. I went ahead and used properties to make a block as I was looking for, and I did it in a way that the property is local to the spawned object. The code will be below, but I feel as though this topic can be closed. Thank you.


import GameLogic#sensors
SMouseOverAny 	= "sMouseOverAny"
SMouseLeft = "sMouseLeft"
ATrackTo	= "aTrackTo"
#looking for the property named "steering" and checking for resource
def trackToResource(cont):
    obj = cont.owner
    if obj['steering'] == 1:
        return
    
    sMouseOver = cont.sensors[SMouseOverAny]
    if "resource" not in sMouseOver.hitObject:
        return


    #check for sensor activation
    if not sMouseOver.positive:
        return


    sMouseLeft = cont.sensors[SMouseLeft]
    if not sMouseLeft.positive:
       return


    #activate trackto actuator with selected target
    aTrackTo = cont.actuators[ATrackTo]
    aTrackTo.target = sMouseOver.hitObject
    obj = cont.owner
    obj['steering'] = 1
    cont.activate(aTrackTo)