Line 118 of TurtleManagement.scala:

  def getVariablesArraySize(turtle: org.nlogo.api.Turtle, breed:
org.nlogo.api.AgentSet): Int = {
    if (breed == _turtles) {
      program.turtlesOwn.size
    } else {
      if (breed == null) throw new IllegalArgumentException("invalid breed")
      val breedOwns = program.breeds(breed.printName).owns
      program.turtlesOwn.size + breedOwns.size
    }
  }

}


So, that means your line

AgentSet breed = world.getBreed("males");


is returning null.

Perhaps the lines in your Java program are being executed before the
Netlogo program even starts, which would mean the environment in Netlogo is
not initialized with the breeds.

My advice would be localize the Java code in such a way that you can
guarantee that it will never execute before the breeds are initialized.

Let me know what you find,
Mike

On Wed, Jul 3, 2019 at 12:30 PM Jake Saunders <jake...@live.co.uk> wrote:

> Hi
>
> Thank you for your help
>
>
> I have since been able to create the turtles using this method the real
> problem is:
>
> I cant create them to be different breeds without getting a invalid breed
> error. the breed is already initialised within the netlogo code but for
> some reason doesn't work. Any insights ?
>
>
> Here is the code:
>
>
> *Java *
>
> World world = (World) cntx.getAgent().world();
>
> AgentSet breed = world.getBreed("males");
>
> Turtle t = world.createTurtle(breed);
>
>
> *Netlogo *
>
> extensions [epiInput];
> Breed [males male];
> Breed [females female ];
>
> males-own [
>   age
>
>
> ]
>
>
>
> *Error *
>
> *java.lang.IllegalArgumentException: invalid breed*
> * at
> org.nlogo.agent.TurtleManagement.getVariablesArraySize(TurtleManagement.scala:122)*
> * at
> org.nlogo.agent.TurtleManagement.getVariablesArraySize$(TurtleManagement.scala:118)*
> * at org.nlogo.agent.World.getVariablesArraySize(World.scala:109)*
> * at org.nlogo.agent.Turtle.<init>(Turtle.java:87)*
> * at org.nlogo.agent.Turtle2D.<init>(Turtle2D.java:12)*
> * at org.nlogo.agent.World2D.createTurtle(World.scala:225)*
> * at demographicInput.createAgents(demographicInput.java:182)*
> * at demographicInput.report(demographicInput.java:67)*
> * at org.nlogo.prim._externreport.report(_externreport.java:31)*
> * at org.nlogo.prim._asm_procedurego_setprocedurevariable_5.perform()*
> * at org.nlogo.nvm.Context.stepConcurrent(Context.java:107)*
> * at org.nlogo.nvm.ConcurrentJob.step(ConcurrentJob.scala:65)*
> * at org.nlogo.job.JobThread.runPrimaryJobs(JobThread.scala:133)*
> * at org.nlogo.job.JobThread.$anonfun$run$1(JobThread.scala:68)*
> * at
> scala.runtime.java8.JFunction0$mcV$sp.apply(JFunction0$mcV$sp.java:12)*
> * at scala.util.control.Exception$Catch.apply(Exception.scala:224)*
> * at org.nlogo.api.Exceptions$.handling(Exceptions.scala:41)*
> * at org.nlogo.job.JobThread.run(JobThread.scala:66)*
>
> Kind regards
> Jake
>
> On Wednesday, July 3, 2019 at 6:07:06 PM UTC+1, Michael Tamillow wrote:
>>
>> Hi Jake,
>>
>> I'll try to help you if I can, but I'm little rusty.
>>
>> I am thinking you could use the 'world' object, it is not in the
>> extension API.
>>
>> For some applications, you may want more power than the controlling API
>> can provide. In these cases, you need to import from the actual Netlogo
>> packages, rather then org.nlogo.api.
>>
>> My imports in the Auction module look like this: Auction Github Link
>> <https://github.com/UnicornMarkets/Auction/blob/master/src/AuctionExtension.scala>
>>
>> import org.nlogo.agent.World
>> import org.nlogo.api.ExtensionException
>> import org.nlogo.{agent, api, core}
>> import core.Syntax._
>> import api.ScalaConversions._ // implicits
>> import scala.collection.mutable.HashMap
>>
>>
>> As you can see, I am importing from org.nlogo.agent.World
>>
>>
>> http://ccl.northwestern.edu/netlogo/docs/scaladoc/org/nlogo/agent/World.html
>>
>> When you look at the documentation for World, you will see a method
>> called createTurtle. I believe this is the method you need. After you
>> create the turtle you can modify the attributes associated with each agent
>> so that the agent is in the proper location with the proper internal
>> states. You can even getOrCreateTurtle if you have clear expectations of
>> what you want.
>>
>> You can see that even though the nlogo.api has a lot of power, if you
>> want unlimited power (and I, for one, do!) you can drill down to actual
>> netlogo code. At one point I needed this line:
>>
>> val turt = turtle.asInstanceOf[agent.Turtle]
>>
>> because there is a method in the nlogo.agent.Turtle object that is not in
>> the  nlogo.api.Turtle. Try that, let me know how it works.
>>
>> Hope that helps,
>> Mike
>>
>>
>> On Wed, Jul 3, 2019 at 7:09 AM Jake Saunders <jak...@live.co.uk> wrote:
>>
>>> Hi
>>>
>>> I am trying to initialise and add agents to a netlogo model through the
>>> extension api.
>>>
>>> This is causing me some issues mostly down to creating the actual agent
>>> adding it directly onto the model. i cannot set an agent variable as i
>>> cannot initialise it (probably due to my own lack of knowledge).
>>>
>>> Can someone please advise me
>>>
>>> Kind regards
>>> Jake Saunders
>>>
>>> --
>>> You received this message because you are subscribed to the Google
>>> Groups "netlogo-devel" group.
>>> To unsubscribe from this group and stop receiving emails from it, send
>>> an email to netlog...@googlegroups.com.
>>> To view this discussion on the web visit
>>> https://groups.google.com/d/msgid/netlogo-devel/fb976ca0-d1b2-4279-be8d-4647c11d8b8b%40googlegroups.com
>>> <https://groups.google.com/d/msgid/netlogo-devel/fb976ca0-d1b2-4279-be8d-4647c11d8b8b%40googlegroups.com?utm_medium=email&utm_source=footer>
>>> .
>>>
>> --
> You received this message because you are subscribed to the Google Groups
> "netlogo-devel" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to netlogo-devel+unsubscr...@googlegroups.com.
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/netlogo-devel/d336d431-64a9-49b0-b778-c50beca3241f%40googlegroups.com
> <https://groups.google.com/d/msgid/netlogo-devel/d336d431-64a9-49b0-b778-c50beca3241f%40googlegroups.com?utm_medium=email&utm_source=footer>
> .
>

-- 
You received this message because you are subscribed to the Google Groups 
"netlogo-devel" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to netlogo-devel+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/netlogo-devel/CAFkCkGdO%3Dta%3D%2BikN9uGzF%2B9vLwHURg6xfG5U3pgTdNzOgO34Wg%40mail.gmail.com.

Reply via email to