3 Pluspunkte 0 Minuspunkte

Ich habe diesen Code gefunden.

func _ready():
    var http_request = HTTPRequest.new()
    add_child(http_request)
    var url = "https://orf.at"
    http_request.connect("request_completed", self, "_on_request_completed")
    http_request.request(url)

func _on_request_completed(result, response_code, headers, body):
    var response = body.get_string_from_utf8()
    print("Response: ", response)

Ich bekomme aber die Fehlermeldung:

Zeile 18:Invalid argument for "connect()" function: argument 2 should be "Callable" but is "res://Node3D.gd".
Zeile 18:Cannot pass a value of type "String" as "int".
Zeile 18:Invalid argument for "connect()" function: argument 3 should be "int" but is "String".

In Zeile 18 steht das

http_request.connect("request_completed", self, "_on_request_completed")
von  

2 Antworten

1 Pluspunkt 0 Minuspunkte

Ändere Zeile 18 in folgendes:

http_request.connect("request_completed", _on_request_completed)
von (542 Punkte)  
0 Pluspunkte 0 Minuspunkte

Du kannst die Methode request_completed.connect() benutzen.

func _ready():
    var http_request = HTTPRequest.new()
    add_child(http_request)
    var url = "https://orf.at"
    http_request.request_completed.connect(_on_request_completed)
    http_request.request(url)

func _on_request_completed(result, response_code, headers, body):
    var response = body.get_string_from_utf8()
    print("Response: ", response)
von (776 Punkte)