Behavior Activation from an outside object

So I am trying to activate a behavior from an object that is not another behavior. Is there a way of doing this?

Then once that behavior is activated, its wakeup criteria wil be say a time event. And eventually the outside object will deactivate it.

It seems like WakeupOnBehaviorPost is right here but the problem is the object doing the initial activation is not a behavior.

Mahalo

I spent many an hour trying to find a good solution for this. The only solutions I came up with were: a) run the triggering code from within a behavior itself, or b) use AWT events and use a WakeupOnAWTEvent.

a) doesn’t work well for intensive code, and b) can be tricky to make work, as AWT events come from other sources as well. Take your pick :slight_smile:

What do you mean by

[quote]run the triggering code from within a behavior itself
[/quote]
The following code doesn’t work. I guess because if the active flag isn’t set the first time, then the behavior never wakes up. One problem is I don’t think you can call initialize() or processStimulus() from any outside objects. If you could, then this should work right?


public void initialize(){
    if(active){
         this.wakeupOn(timeEvt);
    }
}

public void processStimulus(Enumeration criteria){
   if(active){
         this.wakeupOn(timeEvt);
    }
}

Was the above code fragment what you were talking about or something else?

That code doesn’t work, because as you mentioned, only a behaviour (or other wakeupcondition) can trigger another. You HAVE to have the behaviour waiting on some condition.

What I did was have a behaviour that ran every frame, and it checked for various conditions that would result in other behaviours being triggered. This because the suite of available WakeupConditions didn’t fulfil all my needs.

You can do it- I have a bunch of behaviours that also implement ActionListener and are triggered by buttons. You just set the called method to post to itself and use a WakeupOnBehaviourPost to wake it up. There is an example of this in the AWTDemo in the java3d demos directory.

yea, but the problem here is that I don’t want the behavior to wake up on awt events. I have a seperate class that handles awt-events.

Actually, I thought of a senerio where AWT events won’t work -
Take a model that is controlled remotely. It needs to move when it gets information from the network.

Any suggestions?

In that case, you need a polling behaviour: one that triggers based on time and checks for relevant external events. For example, if you wanted to trigger based on network traffic, I’d setup a behaviour that wakes every 100ms (or whatever resolution you want), and checks for network traffic/queued events, then enables the relevant behaviours from there.

I’m not sure about this, because I haven’t really played with events so much, but could you not have your network code post an event when it gets new data and your behaviour implementing EventListener. I think that’s actually about the same as what morbo has suggested, but using the event framework rather than rolling your own.

Ok, This is what I think you could do:

create your own class extended from WakeupCriterion. THere is only 1 method to extend which is hasTriggered(). Set that method to true when you want this behavior to get activated. How does that sound? I’ll try it out to see if that works and post back.

Well, that didn’t work. Apparently there are some private methods in WakeupCriterion that are needed b/c I get a runtime error talking about an abstract method being called.

So I am thinking now to going to Threads or using the polling method previously suggested. It just seems like there is a better way.

Any other hints.

Oh yea, I tried doing the AWTEvent thing too by extending the TextEvent. I couldn’t seem to get the TextEvent to fire so that didn’t work.