Welcome, Guest. Please login or register. Did you miss your activation email?

Author Topic: How to do text selecting?  (Read 1395 times)

0 Members and 1 Guest are viewing this topic.


  • Newbie
  • *
  • Posts: 1
    • View Profile
    • Email
How to do text selecting?
« on: May 31, 2018, 03:00:45 pm »
Well, I'm not too sure how to explain this, but it's somewhat simple. I am creating an an old JRPG battle system where the player chooses to fight or flee. So far I have created the background and display the enemy sprites such in the link below.


Now the part comes in where I have almost absolutely no idea where to begin: player option selection. Now, I can just hard code with a variable that counts in binary with 0 being attack and 1 being flee, but I would like my code to be dynamic in the future. For example, I would probably add more options the player can choose from later such as 'power up' option or a 'use item' option. How would I go about doing this? I've checked the GitHub wiki and tutorials, but found nothing I was looking for, unless I've just missed something. Pointers and examples are much appreciated :)


  • Full Member
  • ***
  • Posts: 136
    • View Profile
Re: How to do text selecting?
« Reply #1 on: May 31, 2018, 05:47:32 pm »
it doesn't has much to do with SFML, but i'd create an enum listing your choices

enum choices{CHOICE_FIGHT, CHOICE_FLEE.....};

Then you have some variable telling where your cursor is :

int currentChoice=0;

Then you listen for the player moving the cursor :

const int maxChoices = 2;

if(key.up && currentChoice >0) currentChoice--;
if(key.down && currentChoice <maxChoices -1) currentChoice++;

... Then you do the appropriate action if he press enter :

case CHOICE_FIGHT: doFight();break;
case CHOICE_FLEE: doFlee();break;

If you need to add more choices, simply increase maxChoices and add a new case in the switch...
Does that answer to your question?
« Last Edit: May 31, 2018, 05:50:33 pm by Phanoo »