gms_p2p_send
Usage: gms_p2p_send ( id, player_id_to, arg0, arg1, arg2... )
Description
Sends the P2P-message with id 'id' to player_id_to.
Replies (12)
Last message on 25 Feb 2020
Is it possible to use this to send an entire array? I would like to use this like this:
array[0] = "TestMessage1"
array[1] = "TestMessage2"
array[2] = "TestMessage3"
etc...
p2p_send(1,gms_p2p_all_in_session,object_index,array)
The only reason why I'd like to use this method over listing each piece of the array individually is because the array could be an undetermined size. I'm not sure what would be the best way to go about this if this method doesn't work? Thanks for the help!
Size43
(Administrator)
on
25 Feb 2020, 19:41:53
Apologies for the delay. If you're using GM:Studio, you can store the data in a ds_map/ds_list and use json_encode to encode/decode the strings into a single JSON-string, which you can send via a P2P message.
Hi Size43!
I just want to make sure of the syntax of this function
i.e.:
var dsl;
dsl=ds_list_create();
ds_list_add(dsl,arg0);
ds_list_add(dsl,arg1);
ds_list_add(dsl,arg2);
ds_list_add(dsl,arg3);
gms_p2p_send(0,gms_self_ismaster(),ds_list_write(dsl));
It's correct???
Size43
(Administrator)
on
9 Nov 2019, 13:16:10
If you're always sending 4 arguments, I'd recommend sending the arguments directly instead of first storing them in a list:
gms_p2p_send(0, gms_self_ismaster(), arg0, arg1, arg2, arg3)
This allows the extension to better optimize the size of the p2p message.
i'm using gms_self_ismaster() in the player id because my game is for two players
When I execute this code: gms_p2p_send(1,gms_self_playerid,5)
I receive "24" for argument2 instead of "5" as I intended.
What could be the problem? I've tried to figure it out before I wrote this but I'm stuck. Please help.
I just realised "24" is the id for the DS list. The arguments are contained in the list for reading. Problem solved.
Hey,
Im trying to use it as follows:
gms_p2p_send(0, string(global.amigo5000), "5000")]/code]
But this error appears:
[code]ERROR in
action number 1
of Async Event: Dialog
for object obj_donar_5000:
Wrong gml type for buffer type
at gml_Script_XGms_cache_player_write (line 24) - buffer_write(global.__send_buffer, buffer_u32, argument1);
############################################################################################
--------------------------------------------------------------------------------------------
stack frame is
gml_Script_XGms_cache_player_write (line 24)
called from - gml_Script_XServer_p2p_send (line 3) - XGms_cache_player_write(_b, argument1);
called from - gml_Script_gms_p2p_send (line 11) - XServer_p2p_send(argument[0], argument[1]);
called from - gml_Object_obj_donar_5000_WebUserInteractionEvent_1 (line 10) - gms_p2p_send(0, string(global.amigo5000), "5000")
I tried to use string and real as argument and as, but still receiving the same error. THX
Hey,
Im trying to use it as follows:
gms_p2p_send(0, string(global.amigo5000), "5000")
But this error appears:
ERROR in
action number 1
of Async Event: Dialog
for object obj_donar_5000:
Wrong gml type for buffer type
at gml_Script_XGms_cache_player_write (line 24) - buffer_write(global.__send_buffer, buffer_u32, argument1);
############################################################################################
--------------------------------------------------------------------------------------------
stack frame is
gml_Script_XGms_cache_player_write (line 24)
called from - gml_Script_XServer_p2p_send (line 3) - XGms_cache_player_write(_b, argument1);
called from - gml_Script_gms_p2p_send (line 11) - XServer_p2p_send(argument[0], argument[1]);
called from - gml_Object_obj_donar_5000_WebUserInteractionEvent_1 (line 10) - gms_p2p_send(0, string(global.amigo5000), "5000")
I tried to use string and real as argument and as, but still receiving the same error. THX
Size, I think I solved it. Now Im not getting this error.
The code Im having now in dialog event(async) in one button object is:
global.amigo5000 = ds_map_find_value(async_load, "result");//got from get_string_async
idplayer=gms_other_find_by_name(global.amigo5000)
show_message(idplayer)
gms_p2p_send(5,idplayer,5000)
But the problem is that the idplayer is always -1 and Im getting the server sided error. Why is it giving me -1?
Thx
Size43
(Administrator)
on
16 Apr 2017, 16:24:58
-1 means it could not find a player with the name you gave.