1 registered members (AndrewAMD),
1,244
guests, and 3
spiders. |
Key:
Admin,
Global Mod,
Mod
|
|
|
sending array
#438853
03/22/14 15:01
03/22/14 15:01
|
Joined: Dec 2011
Posts: 1,823 Netherlands
Reconnoiter
OP
Serious User
|
OP
Serious User
Joined: Dec 2011
Posts: 1,823
Netherlands
|
Hey, it is me spamming the multiplayer boards again, sry . Anyway, my game instantly crashes when I send an array (where I save a handle of an entity in) from the server to the client, in the on_server_event. If I just send a var with the handle, instead of an array, I get no crash. Is it not possible sending arrays with handles?
|
|
|
Re: sending array
[Re: Reconnoiter]
#438854
03/22/14 15:44
03/22/14 15:44
|
Joined: Jan 2002
Posts: 4,225 Germany / Essen
Uhrwerk
Expert
|
Expert
Joined: Jan 2002
Posts: 4,225
Germany / Essen
|
Sending arrays should be possible. But you have an error in your code in line 23.
Always learn from history, to be sure you make the same mistakes again...
|
|
|
Re: sending array
[Re: Reconnoiter]
#438874
03/22/14 19:05
03/22/14 19:05
|
Joined: Jan 2002
Posts: 4,225 Germany / Essen
Uhrwerk
Expert
|
Expert
Joined: Jan 2002
Posts: 4,225
Germany / Essen
|
It was a gentle hint that it's kind of pointless to ask for help when not posting your code. How are we supposed to tell you why its not working when you're not showing us what you did?
Always learn from history, to be sure you make the same mistakes again...
|
|
|
Re: sending array
[Re: Uhrwerk]
#438888
03/22/14 21:47
03/22/14 21:47
|
Joined: Dec 2011
Posts: 1,823 Netherlands
Reconnoiter
OP
Serious User
|
OP
Serious User
Joined: Dec 2011
Posts: 1,823
Netherlands
|
I thought that maybe it was not possible or something like that. Here is the code that saves the handle of players (up to 8 players in theory), I let player 2 (client) wait for testing purposes:
ENTITY* pointer_player[9] = { NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL };
var player_handle[9] = { 0, 0, 0, 0, 0, 0, 0, 0, 0 }; // stores the handle to the player
....
....
wait(-3); //wait till client has received player handles
if (connection == 2) while(1) { wait(1); }
//create player
var i;
for(i = 1; i < 9; i++)
{
if (pointer_player[i] == NULL) { pointer_player[i] = ent_create("MDL_Player.mdl",vector(0,0,100),player_control);
wait(-2); // wait until the handle is ready
player_handle[i] = handle(pointer_player[i]);
break;
}
}
And here is the code that sends the handle from the server to the client:
function on_server_event(void *pVarPtr, var id) // automatically assigned to on_server
{
if (event_type == EVENT_JOIN) {
var i;
for(i = 1; i < 9; i++) {
if (player_handle[i] != 0) send_var_id(id,player_handle[i]); } // send init handles
}
...
I start the server+client (/connection = 3) first, that works fine. Than I join as client after >10 seconds and get an instant crash without an error message. Thanks for watching.
|
|
|
Re: sending array
[Re: Uhrwerk]
#438914
03/23/14 14:06
03/23/14 14:06
|
Joined: Dec 2011
Posts: 1,823 Netherlands
Reconnoiter
OP
Serious User
|
OP
Serious User
Joined: Dec 2011
Posts: 1,823
Netherlands
|
Thanks for the comments. Id love to see the receive code too if theres some. , there is none. I check on the client within a while loop if the player_handle var array is not 0 and if the pointer is null and than retrieve the pointer through ptr_handle. But for testing purposes I disabled it and other functions that manipulate the player pointers. Also you should use send_data_id instead of sending the shit in a for loop because of overhead and cuz its just simplier, saves lines of code and is even faster^^ , sounds like a good idea, thanks . send_var_id expects a pointer to a user defined variable / struct. You're passing an entity pointer to it. , sry but I don't get this. Am I not sending an array (where the entity handle is saved in) through instead of an entity pointer? And why does it work when I send the handle through a var instead of an array?:
var player_handle_test = 0;
...
...
pointer_player_test = ent_create("MDL_Player.mdl",vector(0,0,100),player_control);
wait(-2); // wait until the handle is ready
player_handle_test = handle(pointer_player[i]);
...
...
if (player_handle_test != 0) send_var_id(id,player_handle_test);
So many questions
|
|
|
Re: sending array
[Re: Reconnoiter]
#438915
03/23/14 14:37
03/23/14 14:37
|
Joined: Nov 2006
Posts: 497 Ohio
xbox
Senior Member
|
Senior Member
Joined: Nov 2006
Posts: 497
Ohio
|
send_var_id expects a pointer to a user defined variable / struct. You're passing an entity pointer to it. , sry but I don't get this. Am I not sending an array (where the entity handle is saved in) through instead of an entity pointer? And why does it work when I send the handle through a var instead of an array?: When passing the variable, it works because "send_var_id expects a pointer to a user defined variable" and your variable is just simply a variable you defined. When you try to pass it via array, "You're passing it an entity pointer" which it does not accept because your array is of type ENTITY*, therefore the crash.
|
|
|
Re: sending array
[Re: xbox]
#438928
03/23/14 18:14
03/23/14 18:14
|
Joined: Dec 2011
Posts: 1,823 Netherlands
Reconnoiter
OP
Serious User
|
OP
Serious User
Joined: Dec 2011
Posts: 1,823
Netherlands
|
This is my array that contains the handle:
var player_handle[9] = { 0, 0, 0, 0, 0, 0, 0, 0, 0 }; // stores the handle to the player
So have I defined it wrong for send_var_id? Sry I am kind of newb at this.
|
|
|
|