Mathieu
Mathieu

Reputation: 313

Get patches-own values

how can I get the value of a given netlogo patches-own. I can only get the patches-own names (with .word.program.patchesOwn()) but I don't know how to get their values.

thanks

Upvotes: 1

Views: 441

Answers (1)

Seth Tisue
Seth Tisue

Reputation: 30453

You want the values from all of the patches, or the value from a particular patch, or what?

I'll suppose you want the value from a particular patch.

Assuming, to begin with:

import org.nlogo.headless.HeadlessWorkspace;

HeadlessWorkspace workspace = HeadlessWorkspace.newInstance();
workspace.open("models/Sample Models/Biology/Ants.nlogo");
workspace.command("setup");

Then you don't need anything other than HeadlessWorkspace.report to retrieve a value from a patch, so e.g.:

double food = ((Double) workspace.report("[food] of patch -17 -19")).doubleValue();

Another, more cumbersome solution path involves accessing engine data structures directly:

Patch p = workspace.world().getPatchAt(-17, -19);    
int foodIndex = workspace.world().program().patchesOwn().indexOf("FOOD");
double food = ((Double) p.getPatchVariable(foodIndex)).doubleValue();

Upvotes: 1

Related Questions