Closed cmbarton closed 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
]
])
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
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.
Closing this, but feel free to add comments here if you have further questions.
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.
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.