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

Author Topic: display variables  (Read 5383 times)

0 Members and 1 Guest are viewing this topic.

GAMINGBACON97

  • Newbie
  • *
  • Posts: 42
    • View Profile
    • Email
display variables
« on: September 07, 2015, 07:52:27 pm »
How would I go about displaying a variable to the string, like a score or something?

Jesper Juhl

  • Hero Member
  • *****
  • Posts: 1405
    • View Profile
    • Email
Re: display variables
« Reply #1 on: September 07, 2015, 07:55:01 pm »
Convert to string with std::to_string then draw as sf::Text.
« Last Edit: September 07, 2015, 07:59:11 pm by Jesper Juhl »

GAMINGBACON97

  • Newbie
  • *
  • Posts: 42
    • View Profile
    • Email
Re: display variables
« Reply #2 on: September 07, 2015, 08:08:30 pm »
sf::Text DisplayedScore;
  std::string Score_str = std::to_string(DisplayedScore);//like this?

 

Jesper Juhl

  • Hero Member
  • *****
  • Posts: 1405
    • View Profile
    • Email
Re: display variables
« Reply #3 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.
« Last Edit: September 07, 2015, 08:12:00 pm by Jesper Juhl »

GAMINGBACON97

  • Newbie
  • *
  • Posts: 42
    • View Profile
    • Email
Re: display variables
« Reply #4 on: September 07, 2015, 08:11:02 pm »
well, no I haven't I will though, 1 sec

GAMINGBACON97

  • Newbie
  • *
  • Posts: 42
    • View Profile
    • Email
Re: display variables
« Reply #5 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
 

dabbertorres

  • Hero Member
  • *****
  • Posts: 506
    • View Profile
    • website/blog
Re: display variables
« Reply #6 on: September 07, 2015, 08:40:20 pm »
Check the name of variable you're passing to setString.

ScArL3T

  • Newbie
  • *
  • Posts: 32
    • View Profile
Re: display variables
« Reply #7 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);

GAMINGBACON97

  • Newbie
  • *
  • Posts: 42
    • View Profile
    • Email
Re: display variables
« Reply #8 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.

ScArL3T

  • Newbie
  • *
  • Posts: 32
    • View Profile
Re: display variables
« Reply #9 on: September 07, 2015, 08:48:44 pm »
You don't seem to know what you're doing.  ???

Jesper Juhl

  • Hero Member
  • *****
  • Posts: 1405
    • View Profile
    • Email
Re: display variables
« Reply #10 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.

GAMINGBACON97

  • Newbie
  • *
  • Posts: 42
    • View Profile
    • Email
Re: display variables
« Reply #11 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).

Jesper Juhl

  • Hero Member
  • *****
  • Posts: 1405
    • View Profile
    • Email
Re: display variables
« Reply #12 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.
« Last Edit: September 07, 2015, 09:20:48 pm by Jesper Juhl »

GAMINGBACON97

  • Newbie
  • *
  • Posts: 42
    • View Profile
    • Email
Re: display variables
« Reply #13 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

Satus

  • Guest
Re: display variables
« Reply #14 on: September 07, 2015, 10:20:12 pm »
If you want some gui, try QT or MFC or any other high level gui toolkit.