[ANet] Send char array with an event

Posted By: Razoron

[ANet] Send char array with an event - 09/05/10 11:43

Hi,
to reduce the bandwith, I decided to send data thew a achar array with an event.
The sending function:
Code:
function do_dmg(var to, var dmg)
{
	char sendchr[2];
	
	sendchr[0] = to;
	sendchr[1] = dmg;
	
	enet_clsend_event(EVENT_DAMAGE, sendchr, 2, SERVER);
}


The recieving function:
Code:
function server_damage(var sender, STRING* msg, var size)
{
	char data[2];
	data = _chr(msg);
	
	error(_str(data[0]));
	error(_str(data[1]));
	
	var victim = data[0];
	var dmg = data[1];
	
	BOOL found = FALSE;
	
	if(ent_player[victim] != NULL)
	{
		if(enet_ent_globpointer(ent_player[victim]) != ANET_ERROR)
		{
			ent_player[victim].armor -= dmg;
			enet_send_skills(enet_ent_globpointer(ent_player[victim]), 24, 24, BROADCAST);
			found = TRUE;
		}
	}
}



But I always get chinese characters.
Posted By: SchokoKeks

Re: [ANet] Send char array with an event - 09/05/10 13:48

I think that this is not possible in lite-C (though it is in standard C)

Code:
data = _chr(msg);



Try using pointers or memcopy to get the value from msg->chars (or _chr(msg), should be the same).
Posted By: Razoron

Re: [ANet] Send char array with an event - 09/05/10 15:42

Okay, making the char a pointer did it. Thanks.
For all interested:
Code:
function server_damage(var sender, STRING* msg, var size)
{
	char* data;
	data = _chr(msg);
	
	var victim = data[0];
	var dmg = data[1];
	
	BOOL found = FALSE;
	
	if(ent_player[victim] != NULL)
	{
		if(enet_ent_globpointer(ent_player[victim]) != ANET_ERROR)
		{
			ent_player[victim].armor -= dmg;
			enet_send_skills(enet_ent_globpointer(ent_player[victim]), 24, 24, BROADCAST);
			found = TRUE;
		}
	}
}


© 2024 lite-C Forums