Why do I get error after resuming a coroutine? resume: Condition ' !function ' is true. returned: Variant()

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

I have a little script for a gun. I figured a coroutine would do nicely for handling reloading and reload cancelation. The script seems to work just fine from what I have tested, but I’m getting this error in the debugger:

E 0:00:13.779 resume: Condition ’ !function ’ is true. returned:
Variant() <C++ Source> modules/gdscript/gdscript_function.cpp:1836
@ resume()

I am using Godot 3.2.beta.5. I have tested and the error also occurs with 3.2.1

const CANCEL = true

var _pending_reload

func _reload():
    var result = yield(get_tree().create_timer(.5), "timeout")
    
    _pending_reload = null

    if result and result == CANCEL:
	    return

	bullets = FULL

func reload():
    if not _pending_reload: 
        _pending_reload = _reload()

func use():
    if bullets == 0:
        return

    if _pending_reload:
        _pending_reload.resume(CANCEL)

    # irrelevant fire bullet code

_pending_reload.resume(CANCEL) seems to cause it, as the error appears right after canceling a reload.

Why am I getting this error and how might I fix it?

edit: fixed a typo

:bust_in_silhouette: Reply From: qez008

It seems I didn’t quite understand the error message.
From my understanding the result var is of type bool when the resume() function is called with a bool as its argument, and type variant if the timer completes, as the timeout signal doesn’t have any parameters.

:bust_in_silhouette: Reply From: Karmavil

I would suggest remove result from _reload (completely)