0 votes

I have created a thread to execute a method, but this thread is not generating any output.

extends Node

var thread = null

func _ready():
    thread = Thread.new()
    var err = thread.start(self, "work")

func work():
    print("oi")
    while(true):
        print("oi")

I need to create a thread to be communicating with a TCP socket, however it is not working :(

in Engine by (28 points)

1 Answer

+1 vote
Best answer

It worked when I put an argument to the method.

extends Node

var thread = null



func _ready():
    thread = Thread.new()
    var err = thread.start(self, "work")

func work(userdata):
    print("oi")
    while(true):
        print("oi")

Maybe a bug?

by (28 points)
selected by

The documentation says:

Error start ( Object instance, String method, Variant userdata=NULL, int priority=1 )
Start a new Thread, it will run “method” on object “instance” using “userdata” as an argument and running with “priority”, one of PRIORITY_* enum.

The default value for "userdata" may be NULL, but it's still there and will be passed, so if your work-method doesn't have a parameter to receive it the signature will not match.

Yes... but i can't call a func without args?

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.