CRESS-Surrey / eXtraWidgets

An extension for creating additional interface tabs in the NetLogo GUI and putting custom widgets on them.
MIT License
13 stars 4 forks source link

Document the trick for setting globals from widgets #121

Closed nicolaspayette closed 9 years ago

nicolaspayette commented 9 years ago
to setup-globals-from-widgets
  xw:ask xw:widgets xw:with [ not member? xw:kind ["TAB" "NOTE"] ] [
    run (word "set " xw:key " " maybe-quote xw:get xw:key)
  ]
end

to-report maybe-quote [ value ]
  report ifelse-value is-string? value
    [ (word "\"" value "\"") ]
    [ value ]
end
nicolaspayette commented 9 years ago

@jbadham, maybe you'll want to use the maybe-quote reporter in your code.

nicolaspayette commented 9 years ago

Handling lists:

xw:ask xw:widgets with [ xw:kind != "NOTE" ]
[ run (word "set " xw:key " " format xw:get xw:key)
]      

to-report format [ value ]
  report ifelse-value is-string? value
    [ (word "\"" value "\"") ]
    [ ifelse-value is-list? value
      [ reduce word (sentence "[" (map format value) "]") ]
      [ value ]
    ]
end
nicolaspayette commented 9 years ago

That's in https://github.com/nicolaspayette/eXtraWidgets/wiki/Using-the-extension-with-BehaviorSpace now.