Godot Version
v3.5.3 stable (Linux)
Question
Error message
Invalid get index ‘request_completed’ (on base: ‘HTTPRequest’).
Is this a bug in the Godot engine?
v3.5.3 stable (Linux)
Error message
Invalid get index ‘request_completed’ (on base: ‘HTTPRequest’).
Is this a bug in the Godot engine?
Please provide more information.
extends Node
var my_http_request := HTTPRequest.new()
func _ready():
add_child(my_http_request)
my_http_request.request_completed.connect(self._my_http_request_completed)
_my_http_request()
func _my_http_request():
var my_error = my_http_request.request(Setting.gameUrl + "/test.json")
if my_error != OK:
push_error("HTTPリクエスト中にエラーが発生しました。")
func _my_http_request_completed(my_result, my_response_code, my_headers, my_body):
var my_json = JSON.new()
my_json.parse(my_body.get_string_from_utf8())
var my_response = my_json.get_data()
print(my_response["message"])
No syntax errors.
but a runtime error.
Invalid get index ‘request_completed’ (on base: ‘HTTPRequest’).
Is this a bug in the Godot engine?
Connect the signal like this:
my_http_request.connect("request_completed", self, "_my_http_request_completed")
Connecting signals in Godot 3 and Godot 4 are difference.
Thank you.
I appreciate it.
The runtime error
Invalid get index ‘request_completed’ (on base: ‘HTTPRequest’)
is gone.
But the runtime error
Invalid call. Nonexistent function ‘new’ in base ‘_JSON’.
is displayed on the line
var my_json = JSON.new().
new function not exist in JSON, it will JSON.parse(your_data), check its docs
Thank you.
I appreciate you.
The runtime error
Invalid call. Nonexistent function ‘new’ in base ‘_JSON’.
is gone.
extends Node
var my_http_request := HTTPRequest.new()
func _ready():
add_child(my_http_request)
my_http_request.connect("request_completed", self, "_my_http_request_completed")
_my_http_request()
func _my_http_request():
var my_error = my_http_request.request(Setting.gameUrl + "/test.json")
if my_error != OK:
push_error("HTTPリクエスト中にエラーが発生しました。")
func _my_http_request_completed(my_result, my_response_code, my_headers, my_body):
var my_response = JSON.parse(my_body.get_string_from_utf8())
print(my_response["message"])
runtime error
Invalid get index ‘message’ (on base: ‘JSONParseResult’).
is displayed on the line
print(my_response[“message”])
first only print the “my_response”, see what is the result.
Thank you.
I appreciate you.