system
November 20, 2017, 2:43am
1
Attention
Topic was automatically imported from the old Question2Answer platform.
Asked By
PerduGames
Old Version
Published before Godot 3 was released.
Godot 3:
I’m trying to use this method here: https://github.com/godotengine/godot/blob/master/modules/enet/networked_multiplayer_enet.cpp#L403
but I get error expected 1 arguments.
What is happening is that you are probably calling the “PacketPeer ” class method instead of the “put_packet() ” virtual method of the “NetworkedMultiplayerENet ” class.
I realize that the method is not being called here:
https://github.com/godotengine/godot/blob/master/modules/enet/networked_multiplayer_enet.cpp#L654
I do not know if he should or should not, because if he should, I do not understand why he is not then.
Steps to reproduce:
Create a project with the script below on a node and run:
extends Node
const SERVER_IP = "127.0.0.1"
const SERVER_PORT = 1510
var socketUDP = NetworkedMultiplayerENet.new()
function _ready():
start_client()
send_bytes()
function start_client():
socketUDP.create_client(SERVER_IP, SERVER_PORT)
get_tree().set_network_peer(socketUDP)
socketUDP.set_transfer_mode(socketUDP.TRANSFER_MODE_RELIABLE)
function send_bytes():
var stg = "hello"
var pac = stg.to_utf8()
socketUDP.put_packet(pac, pac.size())
system
November 20, 2017, 5:47am
4
Reply From:
PerduGames
I can understand what is happening.
It is calling the “_put_packet() ” method of the “PacketPeer ” class which has the name in GDScript “put_packet() ” which is the method we call:
"ClassDB::bind_method(D_METHOD(“put_packet”, “buffer”), &PacketPeer::_put_packet);
Error PacketPeer::_get_packet_error() const {
return last_get_error;
}
void PacketPeer::_bind_methods() {
ClassDB::bind_method(D_METHOD("get_var"), &PacketPeer::_bnd_get_var);
ClassDB::bind_method(D_METHOD("put_var", "var"), &PacketPeer::put_var);
ClassDB::bind_method(D_METHOD("get_packet"), &PacketPeer::_get_packet);
ClassDB::bind_method(D_METHOD("put_packet", "buffer"), &PacketPeer::_put_packet);
ClassDB::bind_method(D_METHOD("get_packet_error"), &PacketPeer::_get_packet_error);
ClassDB::bind_method(D_METHOD("get_available_packet_count"), &PacketPeer::get_available_packet_count);
ClassDB::bind_method(D_METHOD("set_allow_object_decoding", "enable"), &PacketPeer::set_allow_object_decoding);
ClassDB::bind_method(D_METHOD("is_object_decoding_allowed"), &PacketPeer::is_object_decoding_allowed);
};
/***************/
void PacketPeerStream::_set_stream_peer(REF p_peer) {
then “_put_packet() ” calls the “put_packet_buffer() ” method:
if (buffer_size == 0)
return OK;
PoolVector<uint8_t>::Write w = r_buffer.write();
for (int i = 0; i < buffer_size; i++)
w[i] = buffer[i];
return OK;
}
Error PacketPeer::put_packet_buffer(const PoolVector<uint8_t> &p_buffer) {
int len = p_buffer.size();
if (len == 0)
return OK;
PoolVector<uint8_t>::Read r = p_buffer.read();
return put_packet(&r[0], len);
}
Error PacketPeer::get_var(Variant &r_variant) const {
that followed in “put_packet_buffer() ” is called the “put_packet() ” which because it is virtual, will call the method of the child class:
return OK;
}
Error PacketPeer::put_packet_buffer(const PoolVector<uint8_t> &p_buffer) {
int len = p_buffer.size();
if (len == 0)
return OK;
PoolVector<uint8_t>::Read r = p_buffer.read();
return put_packet(&r[0], len);
}
Error PacketPeer::get_var(Variant &r_variant) const {
const uint8_t *buffer;
int buffer_size;
Error err = get_packet(&buffer, buffer_size);
if (err)
return err;
This will be called the “put_packet() ” method of the “NetworkedMultiplayerENet ” class.