How can I catch python script run because input value change or trigger?

Are there anything which I can use to catch python RunScript is run because

  • value in Input Parameter are change (may all input or specify input)
  • trigger call

I can use variable to keep last input value of each input e.g. bool int string or list
then compare on every script run
but this not success if input are Tree or set input as Tree Access

example : if value in x or y change will reset a to 0

in above picture b will always counting up
if remove line 24-27 it’s can work as expect, but this miss detection of y (Tree)

File are attached
Test2.ghx (48.3 KB)

Thank you very much

edit: more clearly

You can store variables in a special dictionary which stays in memory for the whole runtime. You can access that from anywhere, so be careful with naming the keys.

But you should try to do everything you can to code state-less. Working around the original intention of Grasshopper can lead to odd side-effects. The intention is to always re-compute!

Thank you very much Tom,

I try sticky as you suggest but seem it not working
Am I do some mistake ?
Is it possible to compare Tree with " == " or " != " operator ?

File are attached
Test3.ghx (71.3 KB)

Idea for this is with really big iteration are cause user feel screen freeze
then I would like to split iteration in small amount and use trigger to looping though that
and give a progress message, like rendering that you can see progressing but need to wait until it finish.
Yes output from this component should not connect to other standard component which will cause many recompute.