0 votes

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. :/

asked Jan 7 in Engine by Dumuz (257 points)

2 Answers

+1 vote
Best answer

If you are talking about judging whether a thread running, you can check this:
https://docs.godotengine.org/en/latest/classes/class_thread.html#class-thread-method-wait-to-finish

If not, you may want to know about "coroutines"?
https://docs.godotengine.org/en/latest/getting_started/scripting/gdscript/gdscript_basics.html#coroutines-with-yield

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

answered Jan 7 by ATom 1 (209 points)
selected Jan 9 by Dumuz

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

I appreciate the multiple resolutions to this issue.

0 votes

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.

answered Jan 7 by TheNewGrant (49 points)

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.

Welcome to Godot Engine Q&A, where you can ask questions and receive answers from other members of the community.

Please make sure to read How to use this Q&A? before posting your first questions.