Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 930937
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 15, 20262026-05-15T20:25:10+00:00 2026-05-15T20:25:10+00:00

I am trying to get coordinates for turtles in NetLogo by using the Java

  • 0

I am trying to get coordinates for turtles in NetLogo by using the Java API. I have managed to get the workspace loaded and have been using the following code that I made:

public static int getX(HeadlessWorkspace workspace, String playerName, int agentNum)
{

    Double doubleX = null;
    int xVal = 0;
    try
    {
        xVal = doubleX.valueOf((workspace.report("[xcor] of "+playerName+" "+agentNum).toString()).trim()).intValue();
    }
    catch(Exception ex)
    {
        ex.printStackTrace();
    }
    return xVal;
}

However, there is one small problem. It is extremely slow when there are more than 5 turtles. When I run the Flocking code with 200 turtles, without getting the coordinates, then I get about 300 ticks in 10 seconds. When I run the code with the coordinates, then each tick takes about 3 seconds. Is there a more efficient way of achieving this?

Thanks,

Nadim

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-15T20:25:10+00:00Added an answer on May 15, 2026 at 8:25 pm

    I managed to find out what the proper way should be. This is the code in the NetLogo mailing list as given by Seth Tisue.

    import org.nlogo.headless.*;
    import org.nlogo.api.*;
    class J {
       public static void main(String[] args) {
          try {
             HeadlessWorkspace ws = HeadlessWorkspace.newInstance();
             ws.openString(org.nlogo.util.Utils.url2String("/system/empty.nlogo"));
             ws.command("cro 8 [ fd 5 ]");
             org.nlogo.api.Turtle turtle =(org.nlogo.api.Turtle) ws.world().turtles().agent(3);
             System.out.println("[xcor] of turtle 3 = " + turtle.xcor());
             ws.dispose();
          }
          catch(Exception ex) {
             ex.printStackTrace();
          }
       }
    }
    

    I have reproduced the code here so it may benefit others. To see a list of what information you can get from Turtle, look at the NetLogo API documentation.

    Nadim

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have been trying to get my geocoder working this morning for the following
I am trying to get the location coordinates using CLLocationManager. Here is my code
I'm writing a simple game in Java and are trying to get the coordinates
I have been trying to get a working algorithm that detects intersection between a
I am trying to get the country name/ code from the coordinates that I
So I have been stuck for a couple of hours trying to get this
I'm trying to get the coordinates of an element on a page. I've been
I am trying to get coordinates from GPS (this actually gives the values for
I am trying to get the coordinates of a component, for example a label.
I am trying get all html links within a string and replace them using

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.