Need help to hold variable output from python function block

hello everyone … I am a beginner in using Grasshopper …
I want to ask something related to my python script block function problem …
I made the function block as follows:

my goal is to calculate the value at input y. The value on input y will be added 1 per program cycle (x).
when i press the x button (activate counter) then the program runs adds y value. The result of adding the value is then issued to the output variable (a).
the problem is if you deactivate the toogle counter button, the output a will be “null” again. Is there a way so that when I deactivate the counter button the variable a still has the same value as the result of the last sum (it doesn’t change to “null” again)

here is my code :

import rhinoscriptsyntax as rs
for t in range(x):
y = y + 1
a = y

is someone can help me?

Hi @christianbayuagung,

Something akin to the code below should work:

if not "val" in globals():
    val = y

for t in xrange(x):
    val += 1

a = val

Let me know, I’m currently away from the computer!

1 Like

sorry for my late reply…
I have tried the code you provided, and it seems to be going well. Thank you for your help