2 Replies - 3593 Views - Last Post: 29 April 2013 - 04:07 PM Rate Topic: -----

#1 StoicStein  Icon User is offline

  • New D.I.C Head

Reputation: 1
  • View blog
  • Posts: 6
  • Joined: 28-March 13

Question: Listening for ActorWorld's step();

Posted 31 March 2013 - 08:16 PM

I'm wondering how I can make my method happen every time ActorWorld's step() method is called.
The only problem with this one is, I don't even know where to start :/
If someone could give me a push in the right direction that would be very helpful.
P.S. I'd like to avoid rewriting or extending the actorworld class

Is This A Good Question/Topic? 0
  • +

Replies To: Question: Listening for ActorWorld's step();

#2 macosxnerd101  Icon User is online

  • Self-Trained Economist
  • member icon




Reputation: 10396
  • View blog
  • Posts: 38,463
  • Joined: 27-December 08

Re: Question: Listening for ActorWorld's step();

Posted 31 March 2013 - 08:19 PM

Those are the only ways to accomplish that- rewriting or extending.
Was This Post Helpful? 0
  • +
  • -

#3 carterf  Icon User is offline

  • New D.I.C Head

Reputation: 2
  • View blog
  • Posts: 13
  • Joined: 28-April 13

Re: Question: Listening for ActorWorld's step();

Posted 29 April 2013 - 04:07 PM

It would make sense to extend actorworld in the following way:
import info.gridworld.actor.ActorWorld;
public class ActorWorldStepEx extends ActorWorld
{
	public void step() //overrides ActorWorld's step
	{
		super.step();
		myMethod();
	}
	private void myMethod()
	{
		//Your Code here
	}
}


However, if you have an actor in the world, you can just add a method call in the act method.


If you really want to do this without extending ActorWorld, you can do this via a helper thread which monitors the state of the world (not at all recommended!).
Was This Post Helpful? 1
  • +
  • -

Page 1 of 1