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
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
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
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 - }
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 - }
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 - }
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 - }
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 - }