gms_other_count

Usage: gms_other_count ( )

Description

Returns the number of players online subtracted by 1 (one, that's you)

Example

//Show the names of all players
var n, player_id, name;
for(n = 0; n < gms_other_count(); n += 1)
{
    player_id = gms_other_find(n);
    name = gms_other_get_string(player_id, "name")
    show_message(name);
}

Replies (21)

Last message on 14 Jan 2017

Dublann on 26 Dec 2016, 21:21:49
Hi everyone!

I dont know why I am not able to use properly the vs functions, therefore I have checked with the function gms_other_count ( ) what says. I have open the game with 2 android devices, the player INIs for each player are correctly loaded, stored, saved...I mean, they are correctly logged in, but when I ask for the show_message(gms_other_count ( )) is always says 0. In fact, the chat is not working!! Both players are not seeing what the other player is sending.

What am I not taking into account?

PS: others days the chat was working well. Any issue with the server?

THX!
Size43 (Administrator) on 3 Jan 2017, 12:55:48
Hey, apologies for my very late response. I've had some issues with my hand that prevented me from using a computer (RSI).

There were some server issues that have now been fixed. Please let me know if you're still having issues.
Dublann on 4 Jan 2017, 19:54:30
Hi Size!

Chat is still not working, but some days ago it was working very well.

The code Im using is:

Step Event:
gms_chat_toggle(1)
gms_chat_set_font(font0)
gms_chat_colors(c_white,0,0)
gms_chat_bind_pos(70,120,1086,500)

Left button event:
global.chat=string(string_upper(get_string("CHAT","")))
gms_chat(global.chat,c_white)

Room end event:
gms_chat_toggle(0)

What is typed is shown in the chat box, but not sent to the others (they are already logged in).
Size43 (Administrator) on 6 Jan 2017, 10:03:29
Could you check what gms_info_isconnected() and gms_info_isloggedin() return right before sending the chat message?
Dublann on 6 Jan 2017, 12:52:31
I have checked gms_other_count(), gms_info_isconnected() and gms_info_isloggedin() just after logged in in both devices with different accounts, and the resutls were 0; 1; 1 respectively.

I did the same just before and just after sending the chat message, and the results were also 0; 1; 1.
Dublann on 10 Jan 2017, 18:55:23
Size, is it related with the problems on sync functions?
Size43 (Administrator) on 10 Jan 2017, 19:02:32
It should not be related.

Could you post the code you're using for logging in?

(Also, just make sure you're not accidentally destroying the GMS object. gms_network needs to be called each step so that the extension can receive data from the server)
Dublann on 10 Jan 2017, 19:15:14
GMS object:

Create event:
gms_init(GMS)
gms_settings(true, 1.0, obj_player, obj_other_player);

if global.recordar=="1"//This variable is true when the button remember is pressed
{
alarm[0]=5
}
else{room_goto(rm_login)}//In this room with get_string you get the user data and execute the script that switch(argument0)...

Alarm0 event:
gms_login_set_password(global.pass1)
gms_login_set_username(global.usuario)
gms_login_execute(scr_login_recordado)//The scrip is the switch(argument0)...

These global var are stored in a local txt file. They are got using get_string function

Step event:
gms_step()

Networking event:
gms_network()

Draw event:
gms_draw()

Game end event:
gms_logout()
Size43 (Administrator) on 11 Jan 2017, 16:37:54
That code looks fine. I'm thinking both clients somehow end up in different sessions. Can you check to see if the session IDs are the same? (gms_session_current_id)
Dublann on 11 Jan 2017, 20:02:26
It says that both players are in the session 0.

Maybe the problem is in the object chat. It is what Im having:

Step event:

gms_chat_toggle(1)
gms_chat_set_font(font0)
gms_chat_colors(c_white,0,0)
gms_chat_bind_pos(70,120,1086,500)

Left released event:
global.chat=string(string_upper(get_string("CHAT","")))

Room end event:
gms_chat_toggle(0)
Size43 (Administrator) on 11 Jan 2017, 21:58:26
Well if the session id is 0, there's definitely something wrong with the login process. The session id should be greater or equal to 1. Make sure you're not accidentially calling gms_login_execute twice (maybe there are two GMS instances in the room?). Also, check if you're getting kicked from the server by setting a script in gms_script_set_kick.
Dublann on 12 Jan 2017, 19:23:05
Size I dont find the problem. This is what i did:

- look for where is gms_login_execute , and it is added only in GMS object. In case I missed something, I added a show_message for each time this function is executed, and it was executed only once during the game.
-There is only 1 object gms in the rooms (it is persistent and placed only in the first room)
- With gms_script_set_kick, I added it into a persisten object in the step event. The scrip just said argument0="KICKEADO". It never appears

Any other idea?
Dublann on 14 Jan 2017, 14:12:09
Another thing that I have done in order to check if the session_id is being modified during the game, is to create a session to join in the first room, and check if this id is changing when I press a key. I have confirmed that the session_id once created is never changed and I keep contected to it.

It seems that when gms_login_execute is called, it does not create a session. It remains me in the session "0" (I have also checked it with the debugger mode). So, it seems to be the reason why I am not able to send/receive chat messages.
Size43 (Administrator) on 14 Jan 2017, 14:20:03
Yeah, that's definitely an issue. The session id will change when logging in, otherwise you're not logged in. Try changing the kick script to

show_message(argument0)


Otherwise you won't know if it was run. Also, could you post the contents of scr_login_recordado?
Dublann on 14 Jan 2017, 14:36:57
I have changed the kick script and nothing happens:

in step event of GMS: gms_script_set_kick(scr_kick)
In script "scr_kick": show_message(argument0)

The scr_login_recordado is having:

switch(argument0)
{
case e_ok:
//show_message("Login OK!");
//instance_create(room_width/2,room_height/2,obj_tiempo)
with(GMS){alarm[1]=5}//This alarm is having room_goto(room_main_centro)
break;
case e_already_logged_in:
show_message("You're already logged in!");
room_goto(rm_login)
break;
default:
show_message(gms_login_error_tostring(argument0));
room_goto(rm_login)
break;
}

I think Im logged in the server, because the player INI are well readed. In fact, on every room they need to be loaded and always they are loaded correctly.
Size43 (Administrator) on 14 Jan 2017, 14:38:40
That's very strange. Would you mind mailing me your project (or a similar one that has the same issue) at gamemakerserver@outlook.com?
Dublann on 14 Jan 2017, 16:05:57
Already sent.

Thank you very much!!
Bluecore on 19 Aug 2016, 07:37:30
I am trying to use this code to display on the title screen how many people are online playing my game however I seem to only get 0 no matter how many instances of the game I do.
Code:

Draw Event:
var PLayerCount
PlayerCount = gms_other_count()

draw_set_font(EightBitOperatorJVE);
draw_text_ext_transformed_colour(x+2,y,string(PlayerCount) + " filled with DETERMINATION!",10,200,2,2,0,c_white,c_white,c_white,c_white,1);
Bluecore on 19 Aug 2016, 07:41:14
Made a small mistake with the var name, fixed it but the same problem still happens.
var PlayerCount
PlayerCount = gms_other_count()

draw_set_font(EightBitOperatorJVE);
draw_text_ext_transformed_colour(x+2,y,string(PlayerCount) + " filled with DETERMINATION!",10,200,2,2,0,c_white,c_white,c_white,c_white,1);
Size43 (Administrator) on 20 Aug 2016, 22:50:22
Hey,

gms_other_count() currently only works when you're logged in. An easy solution to this would be to have a player (which is logged in) periodically write gms_other_count to the GameINI. The GameINI can then be read from the title screen by clients that aren't logged in.

To choose a player, you could use gms_self_ismaster(), which will return true for exactly one player in the game.

Ps. Thank you so much for the donation!
Bluecore on 28 Aug 2016, 00:28:48
Thank you very much for the solution and it was my pleasure! Thanks to you, great things can be accomplished using Game Maker.