This is an entirely different approach, but does just that:
Edit: Also, have a look at the links here regarding solving what you were doing, they demonstrate different approaches to making persistent variables that will be useful for you GHPythoning