0 votes

I am trying to understand the basics of sending data to a server and bringing data back to a device.

Can you please show me an example how I can send a simple numeric value to my server computer, store it in already created .txt document, then call it back to the device?

Thank you for your time!

Godot version 3.2.3
in Engine by (326 points)

1 Answer

0 votes

You should use something like that:

func _ready():
         var xhr = HTTPRequest.new();

        xhr.connect("request_completed", self, "OnRequestCompleted");

          var body = {"num": 5}
          var status = xhr.request("", [], true, HTTPClient.METHOD_POST, body)

if status != OK:
    push_error("Something went wrong :(")

func OnRequestCompleted(result, response_code, headers, body):

You need to create a num_file in your server and write it, for example, in PHP.

I hope this will be useful for you.
MxtApps :)

by (115 points)
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.