Why my function prints [GDScriptFunctionState:1305]??

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

I have a double tap logic

var clicked = false
func double_input(input):
    if Input.is_action_just_released(input):
      clicked = true
      yield(get_tree().create_timer(0.5),"timeout")
      cliked = false
   if clicked == true: 
     if Input.is_action_pressed(input):
       return true

It works fine just as intended but if I print it out, the log will be like this:

null
null
null
null
[GDScriptFunctionState:1305]
true
null

I don’t know why but I deduce that it prints the yield in my function, anyone knows how to deal with this?


EDIT:
I’ve got a workaround. I created a ‘match’ system that filters if it is object,bool or null and it’s working.

InputEventMouseButton already has a doubleclickproperty.

Anyway according to the docs

Calling yield() will immediately return from the current function, with the current frozen state of the same function as the return value.

So this is intended behavior. You probably shouldn’t be using yield() in this situation.

exuin | 2021-04-21 05:18

:bust_in_silhouette: Reply From: avnih

When a func calls yield(), execution of the func stops and returns to whoever called the func. But since the func will resume after the yield is fulfilled, the returning value is the object GDScriptFunctionState which is actually the func object itself. Whenever a func returns this object, you know that it is in yield state.

https://docs.godotengine.org/en/stable/classes/class_gdscriptfunctionstate.html