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

Author Topic: BACKSPACE PROBLEM(please read before condemning this as duplicate :) )  (Read 1473 times)

0 Members and 1 Guest are viewing this topic.

dove96

  • Newbie
  • *
  • Posts: 20
    • View Profile
    • Email
I've been reading about this for 4 hours both docs and threads here but I was not able to make this work properly . i am posting this as new topic again because the threads i went to i guess are dead. I just simply want to ask max of 8 character input and delete characters when backspace is pressed. somehow i got it working but:

  • it deletes the last character, but it replaces it with the backspace character value " ".
question is: what should i do so that the backspace character value is not inserted on the string?

here is my code:

 if (event.type == sf::Event::TextEntered)
                            {
                                if((event.text.unicode < 128)&& playerInput.getSize()< 8 )
                                    {  playerInput.insert(playerInput.getSize(), event.text.unicode);
                                       playerText.setString(playerInput);
                                    }
                            }
                    if(event.type == sf::Event::KeyPressed)
                                    {
                                        if(event.key.code == sf::Keyboard::BackSpace)
                                            {playerInput.erase(playerInput.getSize()-1,2);
                                            playerText.setString(playerInput);}
                                    }
« Last Edit: March 24, 2016, 05:07:33 am by dove96 »
-dove96-

eXpl0it3r

  • SFML Team
  • Hero Member
  • *****
  • Posts: 10800
    • View Profile
    • development blog
    • Email
Next time please either create a new thread from the start or keep the discussion in the already resurrected thread. And don't post on multiple threads.
Just because you don't get a reply within 2.5h (at 3 in the morning in Europe where most people are from), doesn't mean a thread is "dead" or that nobody will look at it. ;)

The forum has an unread posts function, so if a new posts gets written, it will be seen.
« Last Edit: March 24, 2016, 09:13:14 am by eXpl0it3r »
Official FAQ: https://www.sfml-dev.org/faq.php
Official Discord Server: https://discord.gg/nr4X7Fh
——————————————————————
Dev Blog: https://duerrenberger.dev/blog/

eXpl0it3r

  • SFML Team
  • Hero Member
  • *****
  • Posts: 10800
    • View Profile
    • development blog
    • Email
You can always ask questions as long as you invest some time in trying to solve by yourself.
But when you ask, uou shouldn't make three posts about the same problem. ;)
Official FAQ: https://www.sfml-dev.org/faq.php
Official Discord Server: https://discord.gg/nr4X7Fh
——————————————————————
Dev Blog: https://duerrenberger.dev/blog/

 

anything