SFML community forums

Help => General => Topic started by: GAMINGBACON97 on September 07, 2015, 07:52:27 pm

Title: display variables
Post by: GAMINGBACON97 on September 07, 2015, 07:52:27 pm
How would I go about displaying a variable to the string, like a score or something?
Title: Re: display variables
Post by: Jesper Juhl on September 07, 2015, 07:55:01 pm
Convert to string with std::to_string (http://en.cppreference.com/w/cpp/string/basic_string/to_string) then draw as sf::Text (http://www.sfml-dev.org/documentation/2.3/classsf_1_1Text.php).
Title: Re: display variables
Post by: GAMINGBACON97 on September 07, 2015, 08:08:30 pm
sf::Text DisplayedScore;
  std::string Score_str = std::to_string(DisplayedScore);//like this?

 
Title: Re: display variables
Post by: Jesper Juhl on September 07, 2015, 08:10:14 pm
Have you considered trying?
But no. Not quite like that. Please read the documentation I linked to carefully.
Title: Re: display variables
Post by: GAMINGBACON97 on September 07, 2015, 08:11:02 pm
well, no I haven't I will though, 1 sec
Title: Re: display variables
Post by: GAMINGBACON97 on September 07, 2015, 08:36:40 pm
ok so I  have done this, what am I doing wrong?
std::string Score_str = std::to_string(Score);
        DisplayedScore.setString(Score);//I get an error saying more than one constructo applies to
//convert int to string
 
Title: Re: display variables
Post by: dabbertorres on September 07, 2015, 08:40:20 pm
Check the name of variable you're passing to setString.
Title: Re: display variables
Post by: ScArL3T on September 07, 2015, 08:41:43 pm
Dude you should really get a c++ book and actually read it before getting into SFML.

DisplayedScore.setString(Score_str);
Title: Re: display variables
Post by: GAMINGBACON97 on September 07, 2015, 08:43:59 pm
hey don't hate, I've only been at this stuff for a little while now, I know what I'm doing, and getting more and more stuff learned everyday, so just don't hate m8.
Title: Re: display variables
Post by: ScArL3T on September 07, 2015, 08:48:44 pm
You don't seem to know what you're doing.  ???
Title: Re: display variables
Post by: Jesper Juhl on September 07, 2015, 08:56:32 pm
hey don't hate, I've only been at this stuff for a little while now, I know what I'm doing, and getting more and more stuff learned everyday, so just don't hate m8.
Nobody is hating. Just stating plain and simple that you don't seem to know what you are doing.  And I personally agree.  You  are asking very basic and simple questions that clearly show you don't have a strong grasp of C++. I'd advice reading a few good books and doing some simple practice programs.
Also, your questions tend to have little to do with SFML and more to do with your lack of C++ knowledge, so they are not really all that relevant on this forum (IMHO).
Not hating. Just stating facts as I see them.
Title: Re: display variables
Post by: GAMINGBACON97 on September 07, 2015, 09:06:20 pm
well I decided I was sick of looking at a console window, so I decided to learn SFML, I know I don't know C++ all too well, but its my first language, so please Understand I don't always know what I'm doing I understand a lot more than when I started (a few months ago).
Title: Re: display variables
Post by: Jesper Juhl on September 07, 2015, 09:17:44 pm
You are resetting the timer every time ResetPosition() is called. So if it is called more than once every second the value that restart() returns will always be less than a second.
Also. You are not modifying "elapsed" so it will never change its value.
Title: Re: display variables
Post by: GAMINGBACON97 on September 07, 2015, 09:52:03 pm
You are resetting the timer every time ResetPosition() is called. So if it is called more than once every second the value that restart() returns will always be less than a second.
Also. You are not modifying "elapsed" so it will never change its value.
I made a new topic over this
Title: Re: display variables
Post by: Satus on September 07, 2015, 10:20:12 pm
If you want some gui, try QT or MFC or any other high level gui toolkit.