godot-start/script/demo04_signal/thread.gd

30 lines
678 B
GDScript
Raw Blame History

This file contains ambiguous Unicode characters!

This file contains ambiguous Unicode characters that may be confused with others in your current locale. If your use case is intentional and legitimate, you can safely ignore this warning. Use the Escape button to highlight these characters.

extends Button
func _ready():
self.connect("pressed", self, "onButton2")
func onButton2():
var myThread = Thread.new()
print("Create Thread Id: ", myThread)
print("Thread Active: ", myThread.is_active())
myThread.start(self, "threadTest", null, 0)
print()
print("Thread Active: ", myThread.is_active())
var waitForThread = myThread.wait_to_finish() # wait for our thread to finish before moving on
print()
print("Thread is Finished with result: ", waitForThread)
print("Thread Active: ", myThread.is_active())
# 使用thread运行的函数必须有一个参数要不然无法运行
func threadTest(param):
print("thread test start")
return 999