I have been trying to make a drop-down console for my game. I have gotten the console to "drop-down" and all that, but when it comes to input, I have issues (things crash when the user types stuff). In the this particular source file, I have the main function which checks for key presses. If for instance getConsoleInput() detected that the key "G" was pressed, it would call appendLetter("g"). I believe the issue is with appendLetter() itself. When I run the game, I can type one letter, but if I type another, it crashes.
/* ConsoleInput.cpp */
#include "Engine.h"
int timeout = 0;
int lengthText = 0;
std::string line;
std::string sampleText;
void appendLetter(std::string L)
{
line.append(L, lengthText, 1);
lengthText++;
}
void getConsoleInput()
{
if (timeout > 8)
{
//~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~
//Letters (A-Z, space)
//~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~
if (Key_Down(DIK_A))
{
timeout = 0;
appendLetter("a");
}
else if (Key_Down(DIK_B))
{
timeout = 0;
appendLetter("b");
}
//rest of else if statements for other keys
//~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~
//Special Actions (backspace)
//~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~
else if (Key_Down(DIK_BACKSPACE))
{
timeout = 0;
if (lengthText > 0)
{
line.erase(lengthText-1, lengthText);
lengthText--;
}
}
}
timeout++;
}