Hi,
I'm trying to develop a multiplayer RPG using Dark GDK but I'm having issues with text input. Eventually I'll want a chat system but I'll deal with that later.
For now, I'm just trying to give the player a GUI to type the IP of the computer they want to connect to. I want it to behave like a typical single-line text box, with the text appearing on screen as I enter it and backspace to remove the last inputted character.
The problems I'm having are, basically, crashes when trying to connect char* variables together.
dbGetInput() returns a char array (char*), correct?
From what I understand, strcat and strlen are designed to work on char arrays (char variable[size]). My variables have no array brackets [] because if I use them, the dbGetInput line gives me a compiler error. How am I supposed to join two char* strings together? The program crashes every time it sees a strcat or strlen in my code. I don't understand what I'm doing wrong.
Any advice is much appreciated.
Here are segments of the code I have right now:
char* IPAddress;
char* IP;
int IPLength;
void joinGameMenu()
{
while (LoopGDK())
{
dbText(40,70,"IP Address of Host: ");
IP=dbGetEntry();
if (IP!=NULL)
IPLength=strlen(IP); //GAME CRASHES HERE
if (IPLength==0)
{
dbText(300,210,"NULL");
}
if (IPLength!=0)
{
strcat(IPAddress,IP); //GAME CRASHES HERE
IPLength=strlen(IPAddress);
dbText(300,200,"NOT NULL");
}
dbText(200,160,IPAddress); //NEVER DISPLAYS A VALUE
dbText(500,190,dbStr(IPLength));
dbClearEntryBuffer();
if (dbKeyState(156) == 1)
{
inGame = NetConnect(screen_line);
if (inGame==1 && enterKeyPressed==false)
{
dbText(200,200,"CONNECTED TO GAME!");
dbText(200,210,dbStr(inGame));
dbClearEntryBuffer();
enterKeyPressed=true;
}
if (inGame==0 && enterKeyPressed==false)
{
dbText(200,200,"ERROR");
NetDisconnect();
dbClearEntryBuffer();
enterKeyPressed=false;
}
}
if (dbKeyState(14)==1) //BACKSPACE
{
IPAddress[IPLength-2]=NULL;
}
dbSync();
}
return;
}
[EDIT]
Nevermind, I found the problem!
char* IPAddress;
char* IP;
should be:
char* IPAddress = new char[50];
char* IP = new char[20];
heh d'oh