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

Add primitive for setting global variables of child model's #118

Closed qiemem closed 6 years ago

qiemem commented 6 years ago

For example, if you have

globals [ child-global ]

in your child model, you could do ls:set child-global count turtles to set it to the number of turtles in your parent model.

The primary use case I see of this primitive is setting child model parameters. Currently, to pass parameters from the parent model to the child, you have to do something like:

ls:let p1 param1
ls:let p2 param2
ls:let p3 param3
ls:ask child-model [
  set param1 p1
  set param2 p2
  set param3 p3
]

This would let you do:

ls:set param1 param1
ls:set param2 param2
ls:set param3 param3
qiemem commented 6 years ago

It occurs to me that the above syntax does not specify the target child model(s). The obvious syntax would then be:

ls:set child-model param1 param1
ls:set child-model param2 param2
ls:set child-model param3 param3

where child-model could alternatively be a list of models.

However, having to refer to the models repeatedly is pretty annoying, so how about:

(ls:set child-model
  param1 param1
  param2 param2
  param3 param3)
qiemem commented 6 years ago

@arthurhjorth objected to the use of set since this works pretty different that NetLogo's set (since it has to take a model id). How about ls:assign-globals? ls:set-globals? Downside is that the plurality contradicts when only doing a single var.