MaDKit forum

Welcome All !
Please, use explicit topic names when creating new threads. Thanks.

You are not logged in.

#1 2011-10-10 10:58:26

lois.vanhee
Member
Registered: 2011-10-03
Posts: 12

How to get the set of turtles

Dear all,

I would like to access the turtles, in order to display some info about them in a separate panel. How can I access turtles ?
In TurtleActivator, there is a way, but this method is local and non-static. As the turtle set and the patch set are unique objects, is there a way to obtain static access to it ?

Thank you in advance for your help

Offline

#2 2011-10-21 16:45:13

fmichel
Administrator
From: Montpellier
Registered: 2009-03-24
Posts: 176
Website

Re: How to get the set of turtles

Hi,

One way oif accessing the turtle is bu using a TurtleProbe probe within a Viewer or in a Observer. So, you can have access to all the turtles and do some treatment on their attributes. Here is a sample taken from src/edu/turtlekit2/demos/gas :

	public void setup() {
                ...
		allTurtles = new TurtleProbe(getSimulationGroup(),"turtle");
		addProbe(allTurtles);
	}

	public void watch(){
		int cpt = 0;
		//computing how many turtles are on the right side of the wall
		for (final Turtle t : allTurtles.getCurrentAgentsList()) {
			if (t.xcor()>= ((Gas)t).wall)
				cpt++;
		}
               ...
      	}

Offline

Board footer