gms_self_set

Usage: gms_self_set ( "variable", value )

Description

Sets the player's variable to the given value.

Replies (23)

Last message on 8 Mar 2017

Dublann on 21 Jan 2017, 19:10:13
Hi Size,

Im trying to show in a VS room my username and at the same time to see the other player username. For this purpose Im using the gms_self_set function, but Im not sure if im using it correctly.

This is the code Im having in the create event of an object inside the VS room:

gms_self_set("global.mi_nombre",global.mi_nombre)

And another object for reading the other player username has in the create event:

if gms_vs_ready()
{
name=gms_other_get_string(player_id,"name")
}
else
{
name = "ESPERANDO..."
alarm[0]=30//This alarm repeat the code again
}

And in draw event:

draw_set_font(font1)
draw_set_color(c_white)
draw_set_halign(fa_left)
draw_text_outline(x,y,name,2,c_black,16)

The vs config Im having in this website is for 2 players. When I go to this VS room, I cant see the other player username. Am I using correctly the gms_self_set and gms_other_get functions?

Thx!
Dublann on 21 Jan 2017, 19:14:01
I forgot it. When I use this code, this error appears:

FATAL ERROR in
action number 1
of Create Event
for object obj_su_ID:

Variable obj_su_ID.player_id(100033, -2147483648) not set before reading it.
at gml_Object_obj_su_ID_CreateEvent_1 (line 5) - name=gms_other_get_string(player_id,"name")
Size43 (Administrator) on 22 Jan 2017, 09:33:56
The player_id variable is set after the create event, so you cannot use it in the create event.
Dublann on 22 Jan 2017, 14:17:53
Hey,

I have tried to use it in an alarm, in the step event, and directly in the draw event, but in all of them, it says that it doesnt exists. For example in draw event:

FATAL ERROR in
action number 1
of Draw Event
for object obj_su_ID:

Variable obj_su_ID.player_id(100035, -2147483648) not set before reading it.
at gml_Object_obj_su_ID_DrawEvent_1 (line 7) - draw_text(x, y, gms_other_get(player_id, "name"))

Also, I have checked the gms_vs_ready and it returns 0. Now I cant see the player and the other player objects in the game. On yesterday, it returned 1 and I was able to see the objects, if it helps.
Size43 (Administrator) on 30 Jan 2017, 10:54:18
Is obj_su_ID your other player object? The variable only exists in the other player object.
Dublann on 6 Feb 2017, 20:18:38
Hey,
I have been doing some trials and I dont know how it works yet.

I have in an object in the room:
global.mi_nombre=global.usuario//Global.usuario was stablised before
gms_self_set("global.mi_nombre",global.mi_nombre)


And in the other_object, in an alarm event:
su_nombre=gms_other_get_string(player_id,"global.mi_nombre")
show_message(string(su_nombre))//To check if it works


Running the game, it is not giving me the varialbe su_nombre. It is also giving this error:
variable obj_other_player.player_id(100032, -2147483648) not set before reading it.
 at gml_Script_gms_step (line 616) -             room_id     = gms_other_get_real(player_id, "room");
############################################################################################
--------------------------------------------------------------------------------------------
stack frame is
gml_Script_gms_step (line 616)
called from - gml_Object_GMS_StepNormalEvent_1 (line 5) - gms_step()
Dublann on 6 Feb 2017, 20:20:28
Could you please give me an example about how to use the gms_self_set function and the gms_other_get function?

Thank you very much!

PS: I forgot to tell you in the message above, that I also tried to use the gms_self_set in the obj_player and it gave me the same error.
Size43 (Administrator) on 16 Feb 2017, 16:05:28
Are you putting instances of the other player object in the room? The extension eill do that automatically.

Also make sure you set the other player object in gms_settings
Dublann on 25 Feb 2017, 13:50:36
Yes, the obj_other player is in the room, and the settings are
gms_settings(true, 1.0, obj_player, obj_other_player);


I have also added the gms_self_set("global.mi_nombre",global.mi_nombre) to the obj_player and I have added it to the room in case it was the problem, and Im having the same error
of  Step Event0
for object GMS:

variable obj_other_player.player_id(100033, -2147483648) not set before reading it.
 at gml_Script_gms_step (line 616) -             room_id     = gms_other_get_real(player_id, "room");
############################################################################################
--------------------------------------------------------------------------------------------
stack frame is
gml_Script_gms_step (line 616)
called from - gml_Object_GMS_StepNormalEvent_1 (line 5) - gms_step()
Dublann on 25 Feb 2017, 13:53:52
This is exactly what Im having in the objects that are in the room:

Create event of obj_player
global.mi_nombre=global.usuario
gms_self_set("global.mi_nombre",global.mi_nombre)


Alarm0 with time 30 from create event of other_player object
su_nombre=gms_other_get_string(player_id,"global.mi_nombre")
show_message(string(su_nombre))
Size43 (Administrator) on 5 Mar 2017, 19:51:15
Can you add a show_message to the other player object create event, and check to make sure that the message shows up only once when another player logs in, and not at room start or game start?
Dublann on 5 Mar 2017, 20:35:14
I have just done the test, and the message happens when the game start. Why is it happening? Im not using the other_player object in any other room before.
Dublann on 5 Mar 2017, 20:49:23
Sorry Size, I have done another trial and the message appears only when logged in, not when the game starts (in the previous trial the auto loggin was enabled :() or when the room starts.
Dublann on 5 Mar 2017, 21:03:26
One more trial...

After logged in, the message appears 2 times. When I go to the room where the other_player is, the message appears again.

I am going to make more trials, in order to help you/me as much as possible.
Size43 (Administrator) on 6 Mar 2017, 14:10:05
Did you place the obj_other_player in a room (by accident?)? Is there maybe some way that the obj_other_player instance is being created?

Creating instances of obj_other_player should be exclusively done by the extension. If there are other ways the object is created, it will crash.
Dublann on 7 Mar 2017, 19:28:58
I have found the obj_other_player in one room and I have removed it. Now there isnt any obj_other_player in any other room.

So, in the room where I want to share the variable, what have I do? Which objects should I put in? Is necessary to have the obj_player in it? Using the code above in other object different in the room should it work? Im very lost about how to manage the sharing of variables between players.

MANY THX FOR YOUR HELP!!!
Size43 (Administrator) on 8 Mar 2017, 15:19:25
You should set the variable using gms_self_set, then you can retrieve the variable on other clients by calling gms_other_get.

The extension will create obj_other_player instances for you when someone logs in.
Dublann on 8 Mar 2017, 19:03:40
But, should I add the gms_self_set to the obj_player? Should I add the gms_other_get to the obj_other_player? Or do they work in any object?

Should the object with gms_self_set be added into the room? Should the object with gms_other_get be added into the same room?

Thx!!!
Size43 (Administrator) on 8 Mar 2017, 20:04:31
gms_self_set may be called from anywhere.

gms_other_get can also be called from anywhere, but it needs a player ID. Every obj_other_player has a variable player_id after the create event has completed, so it's easiest to put it there. You can also use gms_other_find to obtain a player_id.

obj_player should be added to the room.

obj_other_player should not be added to the room, as the extension will add it for you.
KadePcGames on 8 Dec 2016, 05:39:20
Can You Ues It Like This???
gms_settings("simple_mode",0,obj_player,obj_other_player)
gms_ini_player_write("admin",562,"yes")
gms_ini_player_exists ("admin",562)
gms_self_name()
gms_self_set ("name","<owner>KadePcGames")
idk im a noob
Size43 (Administrator) on 16 Dec 2016, 21:08:59
There needs to be a small delay between gms_settings and the other functions so that it can load the game data from the server.
omarsaurio on 20 Jul 2014, 23:14:19
hey, player variables are saved for how many time? if the player logout or network break, the data continue saved? need something same than player ini but all can read in? any suggest?
Size43 (Administrator) on 21 Jul 2014, 15:14:28
Player variables are not saved. If you need to save data you can use either the PlayerINI or the GameINI. The GameINI will be the same for all players, whereas the PlayerINI is unique for every player.