0 votes
func _2load_scene(path, save_game_values):
    thread = Thread.new()
    print(save_game_values)
    thread.start( self, "_2thread_load", path)
    thread.call_deferred("_2thread_load", path)
    raise() # Show on top.
    progress.visible = true

the code above not works. I want to pass 2 data pieces. First is path the second is tres save file. Why not works?

func load_scene(path):
    thread = Thread.new()
    thread.start( self, "_thread_load", path)
    raise() # Show on top.
    progress.visible = true

This one works but only 1 argumant passed in.

A you may remind calldeferred("2deferredgotoscene", path, savegamevalues) can carry many variables. Why not for the thread?

in Engine by (193 points)

1 Answer

+2 votes
Best answer

The third argument for start function on a thread is a Variant. The idea is instead of being able to pass an indefinite number of variables into the start function, instead you will put all of the values into one data structure, like an Array, and then your thread start function will pull out the values that it needs.
For example:

# make and start thread
func _2load_scene(path, save_game_values):
    var userdata = [path, save_game_values]
    thread = Thread.new()
    thread.start(self, "_thread_load", userdata, Thread.PRIORITY_NORMAL)

# do loading
func _thread_load(usr):
    print("PATH: {0}   SAVE VALUES: {1}".format({0:usr[0], 1:usr[1]})
by (213 points)
selected by

Sir Chansolor, you are a riot, Challanger and admirable person!

Thanks, this is it! You saved me a lot of trouble of making 2 call_deferred then taking variables passing in another function combining them again just for a save purpose.

Thanks, I am a sole game developer maybe we can develop together

I can't still believe you understand me and solve my problem so quickly, Allahcc, The god bless you sir

You are like Spider man on coding

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.