Game Maker Community YoYo Games

Welcome Guest ( Log In | Register )

> Advanced Users Forum Rules

This is a Q&A forum for advanced GML users ONLY. Moderators will remove inappropriate topics. Make sure that you READ these rules prior to posting: Advanced Users Forum Rules

 
Reply to this topicStart new topic
Multiplayer Data Transfer, The received data is -3493433???
Dukembg
post Nov 5 2009, 01:57 AM
Post #1


GMC Member
Group Icon

Group: GMC Member
Posts: 110
Joined: 12-July 04
From: U.S. East
Member No.: 11519



Okay GMC, I need your brains here. I've been working on an online shooter, Dire Days. Currently in W.I.P. and recently I've been getting a lot of error reports with negative array indecies and game lockup.

So, when I play I'm usually hosting and I never get errors... ever.... however players join.. play... and randomly run into errors...

ERRORS : (ALL Happen when a player leaves or joins a game)
CODE
ERROR in
action number 1
of  Step Event
for object obj_game_controller:

In script scr_player:
Error in code at line 44:
                    global.playersname[a] = soc_receive(global.host,SOC_STRING,b);

at position 37: Negative array index

CODE
ERROR in
action number 1
of  Step Event
for object obj_game_controller:

In script scr_player:
Error in code at line 56:
                   if(global.playersin[a] != 0){

at position 28: Unknown variable playersin or array index out of bounds

CODE
ERROR in
action number 1
of Step Event
for object obj_game_controller:

In script scr_player:
Error in code at line 51:
global.playersname[a] = soc_receive(global.host,SOC_STRING,b);

at position 37: Negative array index


HOST SCRIPT: (Host sends the variable "n" which the player receives and uses in an array index... n is never below 0 and never higher than 30)
When a player joins the game :
CODE
120 - if(datatype == 33){
121 -                 a = soc_receive(global.players[n],SOC_SHORT);
122 -                 global.playersname[n] = soc_receive(global.players[n],SOC_STRING,a);
123 -                 scr_add_message(global.playersname[n]+" has joined the game.",c_red);
124 -                obj_game_controller.host_sync_player = true;
125 -                 obj_game_controller.host_sync_timer = 0;
126 -                 obj_game_controller.host_sync_id = n;
127 -                 global.buffer = buffer_create();
128 -                 buffer_add(global.buffer,SOC_BYTE,32);
129 -                 buffer_add(global.buffer,SOC_SHORT,obj_game_controller.ga
metimemilli);
130 -                 buffer_add(global.buffer,SOC_SHORT,obj_game_controller.ga
metimesec);
131 -                 buffer_add(global.buffer,SOC_SHORT,obj_game_controller.ga
metimemin);
132 -                 buffer_add(global.buffer,SOC_SHORT,obj_game_controller.al
lyscore);
133 -                 buffer_add(global.buffer,SOC_SHORT,obj_game_controller.ax
isscore);
134 -                 soc_send(global.players[n],global.buffer);
135 -                 buffer_destroy(global.buffer);
136 -                 global.buffer = buffer_create();
137 -                 buffer_add(global.buffer,SOC_BYTE,33);
138 -                 buffer_add(global.buffer,SOC_SHORT,n);
139 -                 buffer_add(global.buffer,SOC_SHORT,string_length(global.playersname[n]));
140 -                 buffer_add(global.buffer,SOC_STRING,string_length(global.playersname[n]),global.playersname[n]);
141 -                 for(m=0; m<31; m+=1){
142 -                     if(soc_valid(global.players[m]) and m != n){
143 -                         soc_send(global.players[m],global.buffer);
144 -                    }
145 -                 }
146 -                 buffer_destroy(global.buffer);
147 -             }

When a player leaves a game :
CODE
26 - if not(soc_valid(global.players[n])){
27 -             global.numberofplayers-=1;
28 -             obj_game_controller.player_clear_mine = true;
29 -             obj_game_controller.player_clear_timer = 0;
30 -             obj_game_controller.player_clear_id = n;
31 -             global.buffer = buffer_create();
32 -             buffer_add(global.buffer,SOC_BYTE,34);
33 -             buffer_add(global.buffer,SOC_SHORT,n);
34 -             buffer_add(global.buffer,SOC_SHORT,string_length(global.playersname[n]));
35 -            buffer_add(global.buffer,SOC_STRING,string_length(global.playersname[n]),global.playersname[n]);
36 -             for(m=0; m<31; m+=1){
37 -                 if(soc_valid(global.players[m]) and m != n){
38 -                     soc_send(global.players[m],global.buffer);
39 -                 }
40 -             }
41 -             buffer_destroy(global.buffer);
42 -             scr_add_message(global.playersname[n]+" has left the game.",c_red);
43 -             if(global.playersin[n] != 0){
44 -                 global.playersin[n].destroy = true;
45 -             }
46 -             global.playersin[n] = 0;
47 -             global.playersname[n] = "";
48 -             global.playersteam[n] = 0;
49 -             soc_destroy(global.players[n]);
50 -             global.players[n] = 0;
51 -             global.buffer = buffer_create();
52 -             buffer_add(global.buffer,SOC_BYTE,6);
53 -             buffer_add(global.buffer,SOC_SHORT,global.numberofplayers);
54 -             soc_send(global.server,global.buffer);
55 -             buffer_destroy(global.buffer);
56 -             continue;
57 -         }


PLAYER SCRIPT: (WHERE THE ERRORS ARE: "a" is the variable receiving what host sent as "n")
receiving player joined :
CODE
41 - if(datatype == 33){
42 -                 a = soc_receive(global.host,SOC_SHORT);
43 -                 b = soc_receive(global.host,SOC_SHORT);
44 -                 global.playersname[a] = soc_receive(global.host,SOC_STRING,b);
45 -                 global.players[a] = 1;
46 -                 scr_add_message(global.playersname[a]+" has joined the game.",c_red);
47 -             }


receiving player left :
CODE
48 - if(datatype == 34){
49 -                 a = soc_receive(global.host,SOC_SHORT);
50 -                 b = soc_receive(global.host,SOC_SHORT);
51 -                 global.playersname[a] = soc_receive(global.host,SOC_STRING,b);
52 -                 scr_add_message(global.playersname[a]+" has left the game.",c_red);
53 -                 obj_game_controller.player_clear_mine = true;
54 -                 obj_game_controller.player_clear_timer = 0;
55 -                 obj_game_controller.player_clear_id = a;
56 -                 if(global.playersin[a] != 0){
57 -                     global.playersin[a].destroy = true;
58 -                 }
59 -                 global.playersin[a] = 0;
60 -                 global.playersname[a] = "";
61 -                 global.playersteam[a] = 0;
62 -                 global.players[a] = 0;
63 -             }





 

This post has been edited by Dukembg: Nov 5 2009, 02:11 AM
Go to the top of the page
 
+Quote Post
johnjoe
post Nov 5 2009, 09:40 AM
Post #2


GMC Member
Group Icon

Group: GMC Member
Posts: 101
Joined: 19-February 09
Member No.: 128718



you should create the instance [player] after the data is recieved, otherwise it'll cause confusion for the computer. because it takes time to send all those neccessary information for your player, delays are inevitable, therefore whilst the client is being delayed of recieving those information it 4ses any sort of value available for player's id which is in this case is the error - a negative array.

the client connects to the server. if the client is connected, send its id. once the client receives its id from the server, create the instance player and assign the id received to the instance, or better yet set the id as a global variable value. otherwise disconnect the client for the reason that either the server is full, or the client is not connected, instead of throwing error 'negative array' due to it being delayed and using the default array value.

i've dealt with the problem multiple times. and my fixes are most likely similar to that. smile.gif

This post has been edited by johnjoe: Nov 5 2009, 09:42 AM
Go to the top of the page
 
+Quote Post

Reply to this topicStart new topic
1 User(s) are reading this topic (1 Guests and 0 Anonymous Users)
0 Members:

 



RSS Lo-Fi Version Time is now: 23rd November 2009 - 10:51 AM