Godot Version
4.5.1.stable
Question
Could someone please explain the issue with my code?
It seems my method test is not called correctly
# network.gd
...
class RPC extends JSONRPC:
func _init() -> void:
var method_list := _get_class().get_script_method_list()
for method: Dictionary in method_list:
var name := method.get("name") as String
set_method(name, Callable(_get_class(), name))
func _get_class() -> GDScript:
return API
class API:
static func test() -> String:
return "test"
# game.gd
...
func request(callable: Callable, param: Variant = null) -> void:
var method := callable.get_method()
var r := rpc.make_request(
method, param, 1
)
var message := JSON.stringify(r)
peer.send_text(message)
func _on_game_connected() -> void:
print("game connectted")
connection.request(API.test)
# server.gd
...
func _on_connection_open(id: int) -> void:
var connection := connections[id]
while connection.get_available_packet_count():
var packet := connection.get_packet()
var action := packet.get_string_from_utf8()
print(action)
var result := rpc.process_string(action)
print(result)
print("connection open: %d" % id)
result:
{"id":1,"jsonrpc":"2.0","method":"test","params":null}
{"id":1,"jsonrpc":"2.0","result":""}