Best way to preserve one value past "clear-all"?

201 views
Skip to first unread message

wade.s...@gmail.com

unread,
Oct 13, 2021, 8:41:17 AM10/13/21
to netlogo-users
I want to clear everything between runs EXCEPT one value that I want to persist.
What's a good way to do that?

I've tried
(a) write it to a text file and read it back in each time
       BUT ... that won't work for Netlogo Web.

(b) load up some extension like R or PY,  write the value there,
     and read it back in since "clear-all" doesn't clear extension values.

(c) ?? Other ideas?

Am I missing something cleaner? Thank you!
Wade

jeremy...@northwestern.edu

unread,
Oct 13, 2021, 9:58:48 AM10/13/21
to netlogo-users
Hey Wade,


>  Combines the effects of clear-globals, clear-ticks, clear-turtles, clear-patches, clear-drawing, clear-all-plots, and clear-output.

So if you want to keep one value you can add a global variable to store it in, then make a `my-clear-all` procedure that omits the `clear-globals` call but clears the other global values you have.  

Like so:

```
globals [ retain-me x y z ]

to my-clear-all 
  ; manually clear the globals we want reset, leave `retain-me` alone.
  set x 0
  set y 0
  set z 0
  clear-ticks
  clear-turtles
  clear-patches
  clear-drawing
  clear-all-plots
  clear-output
end
```

I hope that helps.

-Jeremy

Jim Lyons

unread,
Oct 13, 2021, 11:36:01 AM10/13/21
to netlogo-users

On Oct 13, 2021, at 8:41 AM, wade.s...@gmail.com <wade.s...@gmail.com> wrote:

I want to clear everything between runs EXCEPT one value that I want to persist.
What's a good way to do that?


A local variable will persist after a clear-all:

to test
 let temp 5
 clear-all
 show temp  ;; shows value 5
end

HTH,
Jim

wade.s...@gmail.com

unread,
Oct 13, 2021, 11:57:03 AM10/13/21
to netlogo-users
Jeremy and Jim, thank you!   I think Jim's solution is what I was looking for.
I never realized that clear-all DIDN'T clear local variables!
Which is sort of cool, in that 'local' variables are in some sense MORE global than 'global' variables!

Wade

Michael Tamillow

unread,
Oct 13, 2021, 2:19:59 PM10/13/21
to wade.s...@gmail.com, netlogo-users
That is interesting! They certainly are local to a namespace that is isolated from the clear-all command.

Sent from my iPhone

On Oct 13, 2021, at 10:57 AM, wade.s...@gmail.com <wade.s...@gmail.com> wrote:


--
You received this message because you are subscribed to the Google Groups "netlogo-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to netlogo-user...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/netlogo-users/28180f1e-1667-4225-ab71-26e3d344a903n%40googlegroups.com.
Message has been deleted

Wade Schuette

unread,
Apr 7, 2023, 3:03:49 PM4/7/23
to Wannes...@hotmail.be, netlogo-users
I ddin't know about local variables.  I do know that to persist across runs of Behavior Space past Setup and clear-all,
I set the variable value in an interface slider.   That persists.

Wade


On Fri, Apr 7, 2023 at 1:56 PM lei...@natur.cuni.cz <Wannes...@hotmail.be> wrote:
Late to the party, my own solution to the problem was creating an input box on my interface, wherein I would store a list of all my variables as a list that was turned into a string.
After clearing everything, I would reassign the values to the variables.
This works because clear-all doesn't touch any interface variables.


to safe-box-in
 
  set safe-box    (word
    (list    
      max-seasonality
      max-survival-difference
      survival-mid-point
      max-fecundity-difference
      fecundity-steepness
      fecundity-mid-point
     
      (word "\"" set-territory-quality "\"")
      alpha-value
      beta-value
      exp-mean  
    )
  )
 
end

to safe-box-out
 
  let the-list runresult safe-box
 
  set max-seasonality item 0 the-list
  set max-survival-difference item 1 the-list
  set survival-steepness item 2 the-list
  set survival-mid-point item 3 the-list
  set max-fecundity-difference item 4 the-list
  set fecundity-steepness item 5 the-list
  set fecundity-mid-point item 6 the-list
 
  set set-territory-quality item 7 the-list
  set alpha-value item 8 the-list
  set beta-value item 9 the-list
  set exp-mean item 10 the-list
 
  set safe-box ""
 
end


Op woensdag 13 oktober 2021 om 20:19:59 UTC+2 schreef mikaelta...@gmail.com:

Wannes...@hotmail.be

unread,
Apr 14, 2023, 10:35:09 AM4/14/23
to netlogo-users
Hi Wade,

My comment was not so much about using sliders, but rather about using a single input box on the interface in which to store a whole slew of different variables (by setting them in the code), allowing for the persistance of variables across runs without cluttering up your entire interface.

Best,
Wannes

Op vrijdag 7 april 2023 om 21:03:49 UTC+2 schreef wade.s...@gmail.com:

Stephen Guerin

unread,
Apr 14, 2023, 11:01:44 AM4/14/23
to wade.s...@gmail.com, netlogo-users
The "Store" extension is designed for net logo web and net logo os persistence:

StoreStore long-lived string data from the model in the user's browser, in a way that persists between recompiles and reloads, all without without user interaction (unlike send-to:file saving).

--
You received this message because you are subscribed to the Google Groups "netlogo-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to netlogo-user...@googlegroups.com.

Wade Schuette

unread,
Apr 14, 2023, 1:50:35 PM4/14/23
to stephen...@redfish.com, netlogo-users
Thanks Stephen!  That's perfect!

Wade
Reply all
Reply to author
Forward
0 new messages