The code below does not work in the script component as expected. @eirannejad
if 'i' not in globals() or reset:
i = 0
i += 1
a = i
globals.gh (10.5 KB)
I know in this example it is possible to achieve the same goal with sticky variables, however globals()
would be necessary in other scenarios.
import scriptcontext as sc
if 'i' not in sc.sticky.keys() or reset:
sc.sticky['i'] = 0
sc.sticky['i'] += 1
a = sc.sticky['i']
1 Like
GhPython script and new script components do not share sticky variables. It would be handy if we could share variables between these two.
Sticky.gh (10.6 KB)
This old conversation might useful for full context here. It would indeed be good for the new editor to behave as much as GHPython as possible when it comes to such features.
opened 09:14PM - 24 Oct 13 UTC
closed 10:32AM - 03 Nov 17 UTC
needs testing
I have been wondering about this one for some time now actually. If you create a… variable, run the script and subsequently delete the variable. The variable still exist in globals().
Is this by design? If so, is there a good reason for this that I might be missing? If not, I propose this issue be considered a bug.
Thanks again for all the hard work,
Anders
1 Like
eirannejad
(Ehsan Iran-Nejad)
April 18, 2023, 6:05pm
4
Working on a fix right now: RH-74305 CPython should keep using the same scope for a script instance like legacy Python
2 Likes