Java-Gaming.org    
Featured games (81)
games approved by the League of Dukes
Games in Showcase (487)
Games in Android Showcase (112)
games submitted by our members
Games in WIP (553)
games currently in development
News: Read the Java Gaming Resources, or peek at the official Java tutorials
 
    Home     Help   Search   Login   Register   
Pages: [1]
  ignore  |  Print  
  Behavior Activation from an outside object  (Read 1346 times)
0 Members and 1 Guest are viewing this topic.
Offline Conzar

Junior Member




There is nothing common about common sense


« Posted 2003-06-19 00:41:03 »

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

Ubuntu
Offline morbo

Senior Newbie





« Reply #1 - Posted 2003-06-19 03:46:03 »

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 Smiley
Offline Conzar

Junior Member




There is nothing common about common sense


« Reply #2 - Posted 2003-06-19 13:40:21 »

What do you mean by
Quote
run the triggering code from within a behavior itself


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?
1  
2  
3  
4  
5  
6  
7  
8  
9  
10  
11  
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?

Ubuntu
Games published by our own members! Check 'em out!
Legends of Yore - The Casual Retro Roguelike
Offline morbo

Senior Newbie





« Reply #3 - Posted 2003-06-19 13:53:40 »

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.
Offline Breakfast

Senior Member




for great justice!


« Reply #4 - Posted 2003-06-19 19:23:21 »

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.
Offline Conzar

Junior Member




There is nothing common about common sense


« Reply #5 - Posted 2003-06-19 21:02:37 »

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?

Ubuntu
Offline morbo

Senior Newbie





« Reply #6 - Posted 2003-06-20 00:09:09 »

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.
Offline Breakfast

Senior Member




for great justice!


« Reply #7 - Posted 2003-06-20 07:54:22 »

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.
Offline Conzar

Junior Member




There is nothing common about common sense


« Reply #8 - Posted 2003-06-20 14:16:05 »

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.

Ubuntu
Offline Conzar

Junior Member




There is nothing common about common sense


« Reply #9 - Posted 2003-06-20 19:44:39 »

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.  

Ubuntu
Pages: [1]
  ignore  |  Print  
 
 
You cannot reply to this message, because it is very, very old.

 

Add your game by posting it in the WIP section,
or publish it in Showcase.

The first screenshot will be displayed as a thumbnail.

TehJavaDev (13 views)
2014-08-28 18:26:30

CopyableCougar4 (25 views)
2014-08-22 19:31:30

atombrot (38 views)
2014-08-19 09:29:53

Tekkerue (31 views)
2014-08-16 06:45:27

Tekkerue (31 views)
2014-08-16 06:22:17

Tekkerue (19 views)
2014-08-16 06:20:21

Tekkerue (29 views)
2014-08-16 06:12:11

Rayexar (66 views)
2014-08-11 02:49:23

BurntPizza (42 views)
2014-08-09 21:09:32

BurntPizza (34 views)
2014-08-08 02:01:56
List of Learning Resources
by Longor1996
2014-08-16 10:40:00

List of Learning Resources
by SilverTiger
2014-08-05 19:33:27

Resources for WIP games
by CogWheelz
2014-08-01 16:20:17

Resources for WIP games
by CogWheelz
2014-08-01 16:19:50

List of Learning Resources
by SilverTiger
2014-07-31 16:29:50

List of Learning Resources
by SilverTiger
2014-07-31 16:26:06

List of Learning Resources
by SilverTiger
2014-07-31 11:54:12

HotSpot Options
by dleskov
2014-07-08 01:59:08
java-gaming.org is not responsible for the content posted by its members, including references to external websites, and other references that may or may not have a relation with our primarily gaming and game production oriented community. inquiries and complaints can be sent via email to the info‑account of the company managing the website of java‑gaming.org
Powered by MySQL Powered by PHP Powered by SMF 1.1.18 | SMF © 2013, Simple Machines | Managed by Enhanced Four Valid XHTML 1.0! Valid CSS!