GHPython: Function to compare a value with a value a second before

I’m trying to run a python script to check wether the count of iterations of the Kangaroo solver has changed within a specific time frame.

The idea behind that is to have a component that indicates wether a Kangaroo solver is running or not. I want to use that component in an algortihm with several Kangaroo solvers, so that I don’t have to turn them individually on and off everytime I’m changing something at the beginning.
I cannot let them run as the file is quite heavy, thus I run them seperately.

So I did some research on Python and wrote the following code:

import time

s = 1.0

def check():
    prev_x = None
    while True:
        if prev_x != x:
            print("False")
        else:
            print("True")
        prev_x = x
        time.sleep(s)
        return prev_x

check()

Unfortunately its not working as the output does not change between True and False when I start or stop the solver.

Yet, I’m a bloody beginenr in Python so maybe someone with more expertise could help ?
Thanks in advance !

kangaroo_python_test.gh (24.2 KB)

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 :slight_smile:

2 Likes

Perfect @AndersDeleuran !!
Couldn’t find that on my own, thank you for the hint !

1 Like

No worries, if you start jumping through too many hoops you can also script a custom solver:

1 Like

oh wow, well seems like a big step for a Python beginner but maybe that’s the perfect start to finally tackle it properly !!
Thanks again, perfect input :slight_smile:

1 Like