2
votes

I am currently setting a multi-level model, and am hoping to use the NetLogo LevelSpace extension. I want the parent model to request the value of a global variable from a child model, but am having a little difficulty with the syntax. I can find examples of requests for information from agents e.g.

let turtle-id 0
(ls:report model-id [ [ color ] of turtle ? ] turtle-id)

but this doesn't seem to work for global variables e.g., I would like to do something like:

ls:report model-id [child-global-variable]

Is this possible, or am I completely missing the way that LevelSpace works?

2

2 Answers

1
votes
ls:report model-id [child-global-variable]

will actually work just fine, though I slightly prefer using ls:of, just because it matches of:

[child-global-variable] ls:of model-id

That said, all the code that we're discussing right now requires the upcoming version of LevelSpace (which will run on the upcoming version of NetLogo, 6.0).

You can download the version that runs with NetLogo 5.3.1 here: https://github.com/NetLogo/LevelSpace/releases/tag/0.1

That version requires that code be passed between models in strings. So you have to do:

"child-global-variable" ls:of model-id

You can find the documentation for that version here: https://github.com/NetLogo/LevelSpace/blob/c3f78f45217e34cd31b18a246e4749e74209f29f/README.md

Sorry for the confusion!

1
votes

I have found a solution: create a function in the child model that reports the variable:

to-report report-variable
  report variable
end

Then, I can call this function from the parent-model:

show "report-variable" ls:of ls:models

Not sure if this is the most efficient way to do it, but it seems to work.