If you look at the structure of the key checks, you have this:
if (event.type == sf::Event::KeyPressed && event.key.code == sf::Keyboard::Return)
{
// Return pressed
if(event.type == sf::Event::KeyPressed && event.key.code == sf::Keyboard::Num1)
{
// Option 1
}
else
{
// Option 2
}
}
The second if is inside of the first if. When the first if is true, the key must be Return. Therefore the second if can never be true, the key can't be both Return and Num1 at the same time. Each pass of the event while loop only gets a single key event at a time.
The else is then the chosen path for any situation that isn't pressing Num1, such as no key pressed (but there was one to reach this far) or any key besides Num1. So the else is run because Return isn't Num1.
The simplest change to not immediately run the else code would be:
if (event.type == sf::Event::KeyPressed && event.key.code == sf::Keyboard::Return)
{
}
else if(event.type == sf::Event::KeyPressed && event.key.code == sf::Keyboard::Num1)
{
// Option 1
}
else if(event.type == sf::Event::KeyPressed && event.key.code == sf::Keyboard::Num2)
{
// Option 2
}
Or you could group the common part (event was a key press) better into:
if (event.type == sf::Event::KeyPressed)
{
if(event.key.code == sf::Keyboard::Return)
{
}
else if(event.key.code == sf::Keyboard::Num1)
{
}
else if(event.key.code == sf::Keyboard::Num2)
{
}
}
For the actual text adventure part, there's a few ways to go. Off the top of my head, for each node in the story you'd have the following data:
-collection of text lines to describe the story node
-list of choices, each of which takes you to another story node.
I'd probably use something like:
class Choice
{
public:
std::string choiceText;
int destinationNode;
};
class Node
{
public:
std::vector<std::string> description;
std::vector<Choice> choices;
};
std::vector<Node> story;
So a choice has destinationNode, which is the index number of the next node (in the story vector) to jump to. Each Node has a vector of strings (what your text_array was doing) and a vector of choices.
Filling that data could be done in code, but having a loading system and maybe a JSON file to store it all would make it easier (well, once you understand JSON loading, it's VERY useful).
Maybe instead of index numbers for nodes, you could store them in an std::map and give each node a text name like "CastleEntrance".
Anyway, those are my half awake ramblings.
![Smiley :)](https://www.sfml-dev.org/forums/Smileys/default/smiley.gif)