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

in Engine by (355 points)

2 Answers

+1 vote
Best answer

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

by (206 points)
selected by

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.

by (71 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.
Social login is currently unavailable. If you've previously logged in with a Facebook or GitHub account, use the I forgot my password link in the login box to set a password for your account. If you still can't access your account, send an email to webmaster@godotengine.org with your username.