How to check if a function is active or not?

:information_source: Attention Topic was automatically imported from the old Question2Answer platform.
:bust_in_silhouette: Asked By Dumuz

I trying to find a way to have the game check if one of my functions are being used or not. I thought it was either is_valid() or is_active(), but that doesn’t seem to work.

I can’t seem find the answer in docs or on google. :confused:

:bust_in_silhouette: Reply From: TheNewGrant

I think that an easy way to see if a function was running was to add a print statement whenever it becomes active.

print("I'm active")

Then when it should run you can look in the output box at the bottom (during and after running) to check to see if it’s running.

You can also debug the game by clicking next to the numbers (left) in the script until a red box appears at the beginning and end of the function so it would close when it runs (deactivate same way as activate). If you know when it’s running you won’t need to check.

Unless you are trying something else and this is not relevant to you. Then my apologies.

Thanks for the reply, I guess I should have been more specific. I’m looking for a way to check if a function is active to use in an if statement. I.E:

func _process():
     if _some_function().is_active(): # I know it doesn't work but something like this.
         #do something

This way, I can have something only do something if another function is being used, or not used, at the moment.

Dumuz | 2020-01-07 03:55

:bust_in_silhouette: Reply From: ATom 1

If you are talking about judging whether a thread running, you can check this:

If not, you may want to know about “coroutines”?

If none of this is what you want, maybe you don’t understand the stack well?
Anyway,you can take a more direct approach. Define a unique bool value for the your function, set it to true at the beginning of the function, and false at the end

agree, but maybe better than a bool would be to store a count of calls, along with last call time.

Jason Swearingen | 2020-01-07 13:22

I appreciate the multiple resolutions to this issue.

Dumuz | 2020-01-09 01:43