Gamestudio Links
Zorro Links
Newest Posts
Change chart colours
by 7th_zorro. 05/11/24 09:25
Data from CSV not parsed correctly
by dr_panther. 05/06/24 18:50
AUM Magazine
Latest Screens
The Bible Game
A psychological thriller game
SHADOW (2014)
DEAD TASTE
Who's Online Now
2 registered members (AndrewAMD, dr_panther), 1,290 guests, and 4 spiders.
Key: Admin, Global Mod, Mod
Newest Members
Hanky27, firatv, wandaluciaia, Mega_Rod, EternallyCurious
19051 Registered Users
Previous Thread
Next Thread
Print Thread
Rate Thread
Send_Var for an ENTITY** #424152
06/11/13 09:56
06/11/13 09:56
Joined: Jul 2008
Posts: 168
8
82RJZAE Offline OP
Member
82RJZAE  Offline OP
Member
8

Joined: Jul 2008
Posts: 168
I'm not sure what I'm doing wrong, but I have an ENTITY** spawn_places that I initialize on the server via
Code:
spawn_places = sys_malloc(sizeof(ENTITY*)*size);

and I fill each array element with ENTITY* pointers.

When a player connects, I run on the client (after receiving the sizeof_spawn_places):
Code:
spawn_places = sys_malloc(sizeof(ENTITY*)*sizeof_spawn_places);
client_ask_for_spawn_places = 1;
send_var_to(NULL,client_ask_for_spawn_places);


And the server EVENT code:
Code:
client_ask_for_spawn_places = 0;
void on_server_event(void* ptr, var cl_id)
{
	switch(event_type)
	{
		case EVENT_VAR:
			if(ptr == &client_ask_for_spawn_places){ 
				send_var_id(cl_id,&spawn_places);
				
			}
			break;
	}
}



However, when I try to access spawn_places[0] as an ENTITY* on the client: my game crashes. For some reason the ENTITY** array isn't being sent properly; I can access the ENTITY** properly on the server. I do this exact same method for sending a variable and it works. What am I doing wrong?

Last edited by 82RJZAE; 06/11/13 09:59.
Re: Send_Var for an ENTITY** [Re: 82RJZAE] #424170
06/11/13 14:55
06/11/13 14:55

M
Malice
Unregistered
Malice
Unregistered
M



EDIT* Remove because better reply below...

Last edited by Malice; 06/11/13 15:09.
Re: Send_Var for an ENTITY** [Re: 82RJZAE] #424174
06/11/13 15:00
06/11/13 15:00
Joined: Nov 2011
Posts: 274
de
lemming Offline
Member
lemming  Offline
Member

Joined: Nov 2011
Posts: 274
de
ENTITY* is a POINTER to an entity object. The pointer is ONLY valid on the system that created it. In your case the server. Sending the pointer to another system will result in a dangling pointer and a crash or unexpected behavior. You have to send the clients the information they need to create their own entities (and pointers).

edit:// If you have synchronised entities make an array with handles instead of pointers. I think they are valid over network.

edit2:// Furthermore you need send_data_id, as send_var_id only sends one var (4 Byte).

Last edited by lemming; 06/11/13 15:06.
Re: Send_Var for an ENTITY** [Re: lemming] #424201
06/11/13 19:41
06/11/13 19:41
Joined: Jul 2008
Posts: 168
8
82RJZAE Offline OP
Member
82RJZAE  Offline OP
Member
8

Joined: Jul 2008
Posts: 168
Thanks. That clarifies my problem then! laugh


Moderated by  HeelX, Spirit 

Gamestudio download | chip programmers | Zorro platform | shop | Data Protection Policy

oP group Germany GmbH | Birkenstr. 25-27 | 63549 Ronneburg / Germany | info (at) opgroup.de

Powered by UBB.threads™ PHP Forum Software 7.7.1