Load scene thread.new function accepts multiple values?

:information_source: Attention Topic was automatically imported from the old Question2Answer platform.
:bust_in_silhouette: Asked By Okan Ozdemir
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 call_deferred(“_2deferred_goto_scene”, path, save_game_values) can carry many variables. Why not for the thread?

:bust_in_silhouette: Reply From: ichster

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]})
    

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

Okan Ozdemir | 2020-03-23 17:04

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

Okan Ozdemir | 2020-03-23 17:21