I have an external source switching from false to true, and if it detects an object it updates a number - how can I count each time the number changes? I tried python with a global() variable… no luck?
This script should work:
from scriptcontext import sticky if "changes" not in sticky.keys(): sticky["changes"] = 0 if "current" not in sticky.keys(): sticky["current"] = Input if Input != sticky["current"]: print "Value Change" sticky["current"] = Input sticky["changes"] += 1 if Reset: if "changes" in sticky.keys(): sticky.pop("current") sticky.pop("changes") if "changes" in sticky.keys(): c = sticky["changes"]
count_changes.gh (14.2 KB)
you’re a legend, second time you’ve helped me!
Thanks, @karls. I’m also a fan of your YouTube videos.
Hi Karls, it helps with debugging if you provide an example of what didn’t work. Anywho, one really doesn’t need
sticky to make persistent variables in GHPython (and if one does use it, it’s probably best to append the component guid onto the variable key name in the
sticky to prevent unexpected behaviours). Here’s a simple implementation using the
if "foo" not in globals() method:
If you need a dynamic counter, have a look at this implementation: