0 votes

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:

func talk_to_server(url, mode, data):
       \\connect to server and retrieves data. 

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.

in Engine by (290 points)

Did you tryHTTPRequest? It gets the answer with a signal, so you would not need a thread http://docs.godotengine.org/en/stable/classes/class_httprequest.html

Sorry late, I missed your reply, so HTTP request doesn't block the main thread?

Well, even the example in the doc is not using a thread: http://docs.godotengine.org/en/latest/learning/features/networking/http_client_class.html?highlight=HttpClient

Did you have a look at the doc I linked above?

Please log in or register to answer this question.

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.