Hi guys, I have been trying to get a multiplayer netowrk... thingy... working. But I am having some problems with the messages.
This is the code recieving the messages:
if (agk::GetNetworkNumClients(networkID) > 0){
if (agk::GetRawKeyState(35)){
agk::CloseNetwork(networkID);
}
//Reading messages from other clients / host
int msg = agk::GetNetworkMessage(networkID);
while (msg > 0){
char* msgType = agk::GetNetworkMessageString(networkID);
if (msgType = "Sector data"){
sectors[0].asteroidAmount = agk::GetNetworkMessageInteger(msg);
for (int i = 0; i < sectors[0].asteroidAmount; i++){
sectors[0].asteroids[i].Type = agk::GetNetworkMessageInteger(msg);
sectors[0].asteroids[i].x = agk::GetNetworkMessageFloat(msg);
sectors[0].asteroids[i].y = agk::GetNetworkMessageFloat(msg);
}
}
agk::DeleteNetworkMessage(msg);
msg = 0;
msg = agk::GetNetworkMessage(networkID);
}
agk::PrintC("SectorName: ");agk::Print(sectors[0].name);
agk::PrintC("Sector contains: ");agk::Print(sectors[0].asteroidAmount);
for (int i = 0; i < sectors[0].asteroidAmount; i++){
agk::PrintC("Asteroid type ");agk::PrintC(sectors[0].asteroids[i].Type);agk::PrintC(" X: ");agk::Print(agk::Str(sectors[0].asteroids[i].x, 0));
}
}
int client = agk::GetNetworkFirstClient(networkID);
while (client != 0){
agk::Print(agk::GetNetworkClientName(networkID, client));
//Checking if the client is still there
if (agk::GetNetworkClientDisconnected(networkID, client) == 1){
agk::DeleteNetworkClient(networkID, client);
}
else{
//Only sending messages when the space key has been pressed
if (agk::GetRawKeyState(32) == 1){
//Sending data about the sector that the client is in
int messageID = agk::CreateNetworkMessage();
//Attatching a string telling the client what this message is about
agk::AddNetworkMessageString(messageID, "Sector data");
//Seding the data
//Sending variables relating to the asteroids
agk::AddNetworkMessageInteger(messageID, sectors[0].asteroidAmount);
for (int i = 0; i < sectors[0].asteroidAmount; i++){
agk::AddNetworkMessageInteger(messageID, sectors[0].asteroids[i].Type);
agk::AddNetworkMessageFloat(messageID, sectors[0].asteroids[i].x);
agk::AddNetworkMessageFloat(messageID, sectors[0].asteroids[i].y);
}
//Sending the message
agk::SendNetworkMessage(networkID, 0, messageID);
}
}
client = agk::GetNetworkNextClient(networkID);
}
//Only sending messages when the space key has been pressed
if (agk::GetRawKeyState(32) == 1){
//Sending data about the sector that the client is in
int messageID = agk::CreateNetworkMessage();
//Attatching a string telling the client what this message is about
agk::AddNetworkMessageString(messageID, "Sector data");
//Seding the data
//Sending variables relating to the asteroids
agk::AddNetworkMessageInteger(messageID, sectors[0].asteroidAmount);
for (int i = 0; i < sectors[0].asteroidAmount; i++){
agk::AddNetworkMessageInteger(messageID, sectors[0].asteroids[i].Type);
agk::AddNetworkMessageFloat(messageID, sectors[0].asteroids[i].x);
agk::AddNetworkMessageFloat(messageID, sectors[0].asteroids[i].y);
}
//Sending the message
agk::SendNetworkMessage(networkID, client, messageID);
}
}
However, the clinet spits out "Message does not exist 10001" and if I use the debugger in VS2010, GetNetworkMessage returns a bigger ID each frame and the DeleteNetworkMessage command dosn't seem to do anything at all. Am I doing something wrong, or is this yet another bug in AppGameKit? Im using 1085 BTW