Attention | Topic was automatically imported from the old Question2Answer platform. | |
Asked By | stubbsy345 | |
Old Version | Published before Godot 3 was released. |
I cannot figure out how to properly use a thread for my required usage.
I am sending a POST http request from which I get a return value. The problem I am having currently is while this request is being sent the game holds and the loading cursor appears, which doesn’t look great. I an animation to be playing while the request is returning but the game should not stop while this is happening. The basic outline of my code is below:
func retrieve_data:
var data = get_node("node").get_data() \\this may be a number of things
get_node("/root/httpclient").talk_to_server(url, mode, data)
func print_answer:
\\data is parsed then printed:
get_node("label").set_text(dataText)
func talk_to_server(url, mode, data):
\\connect to server and retrieves data.
get_node("/root/panel").print_answer(returneddata)
This works well for my needs but I want to use it in a thread so that the game doesn’t stop while it is occurring. Also, so that I can play an animation while waiting for it to return.
I have tried a couple of examples of using threads but can’t get it to work for myself.
Did you tryHTTPRequest
? It gets the answer with a signal, so you would not need a thread HTTPRequest — Godot Engine (stable) documentation in English
Zylann | 2017-10-06 12:55
Sorry late, I missed your reply, so HTTP request doesn’t block the main thread?
stubbsy345 | 2017-11-06 14:07
Well, even the example in the doc is not using a thread: HTTP client class — Godot Engine (latest) documentation in English
Did you have a look at the doc I linked above?
Zylann | 2017-11-06 21:15