Nonexistant function 'is_active' in base 'Nil'

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

i create an unassigned var called thread.

    var thread

in ready i set thread as below

    thread = Thread.new()

in process i check if the thread is not active by doing

	if not thread.is_active():

This works fine in one gdscript I am using, but doesn’t work in another?? I get the error as written in the title.

the two scripts are functionally identical when it comes to this point in threading, but only one seems to recognise thread as being a Thread at this point, while the other sees it as Nil

setting the unassigned var to this ‘fixes’ the issue,

var thread = Thread.new()

but later in the script I call

thread.wait_to_finish()

and I get this error:

wait_to_finish: Thread must exist to wait for its completion

The really confusing thing to me if it’s set up identically in a prior script and doesn’t give these errors at all. Any ideas?

:bust_in_silhouette: Reply From: Inces

This is some unintuitive bollock with threads :slight_smile:
I couldn’t get this until i saw this, I hope it will enlighten you too :