NetLogo / LevelSpace

This is the LevelSpace extension repository. LevelSpace allows you to run NetLogo models |: from inside NetLogo models :|
Other
19 stars 8 forks source link

ls:create follow up commands #142

Closed cmbarton closed 2 years ago

cmbarton commented 2 years ago

I'm not sure if this is an issue with code or documentation. I am trying out level space with an advanced modeling class.

In the docs it looks like you can follow up a ls:create model num with a series of commands in brackets. This would be ideal for parameterizing a set of child models. But several things happen.

  1. ls:create model num [some command] raises an error of "Expected command". If I put the entire statement in parentheses the error is not raised.
  2. If I do put the command in parens, I still cannot seem to issue commands. Specifically, I cannot assign a value to a variable (even a global variable) in a child model. I get an error "Nothing named [var] has been defined".

So what can go into the brackets after an ls:create command? The single example in the docs is not very helpful in this regard.

Any advice is appreciated.

qiemem commented 2 years ago

Check out the example in the docs:

https://ccl.northwestern.edu/netlogo/docs/ls.html#ls:create-models

So (and I admit this is rather confusing), first you have to add parentheses around the whole thing. This is due to a limitation with optional arguments for extension procedures. Second, the command isn't just a command block, but an anonymous procedure that takes the model id as an argument. Finally, the command isn't run in the child model but the parent model. This is because often you need to do something with a model's id before you do something with the model itself, such as storing it in a variable, or using it to pass variables to the model. So, the full code to run a command in the child model after creation is:

(ls:create-model "my-model.nlogo" [ model-id ->
  ls:ask model-id [
    setup
  ]
])
cmbarton commented 2 years ago

Thanks for the quick and very helpful reply. I had hoped this worked more like an agent create command.

If you don't mind, I have an unrelated question. Is there any way that a child model can access information about the world of a parent model (in particular the patch landscape)? Can both a child and parent model be running levelspace to access each other's code and variable values?

Cheers Michael

qiemem commented 2 years ago

Sure thing!

The only way for a child model to access information from a parent model is for the parent model to explicitly pass that information to the child model via ls:let (as a local variable), ls:assign (assigning one of the child's global variables to the information), or as an argument to ls:ask or ls:report, though generally ls:let is cleaner than that.

LaCuneta commented 2 years ago

Closing this, but feel free to add comments here if you have further questions.