Problem with SFML text

Hi, my text for the score and difficulty doesn't seem to work. They are both appearing twice and not updating. The score text worked fine until I inserted the difficulty text and I can't seem to find the problem.
http://oi44.tinypic.com/1040lrb.jpg

Would appreciate some help! Note that I'm not an experienced programmer nor is English my primary language.

I'll just post the full code:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
#include "stdafx.h"
#include <iostream>
#include <sstream>
#include <SFML/Graphics.hpp>


int main()
{
	sf::ContextSettings settings;
	//settings.antialiasingLevel = 8;

    sf::RenderWindow window(sf::VideoMode(800, 800), "RGB Game", sf::Style::Default, settings);

    sf::CircleShape shape(300.f);
    shape.setFillColor(sf::Color::Green);
	shape.setOutlineThickness(20.f);
	shape.setOutlineColor(sf::Color::Green);
	shape.setPosition(100.f, 100.f);
	shape.setPointCount(100);
	

	sf::Font font;
	if(!font.loadFromFile("Advert.ttf"))
		std::cout << "An error when loading from file!" << std::endl;

	sf::Text text;
	text.setFont(font);
	text.setString("Green");

	sf::Text score;
	score.setFont(font);
	score.setPosition(600.f, 0.f);
	int scoreText = 0;

	sf::Text diffText;
	diffText.setFont(font);
	diffText.setPosition(600.f, 50.f);
	int diff = 2;

	sf::Text end;
	end.setFont(font);
	end.setString("Press return to retry!");
	end.setPosition(150.f, 350.f);

	sf::Text changeDiff;
	changeDiff.setFont(font);
	changeDiff.setString("Press arrows to change difficulty!");
	changeDiff.setPosition(150.f, 400.f);

	sf::Text exit;
	exit.setFont(font);
	exit.setString("Press escape to exit!");
	exit.setPosition(150.f, 450.f);

	sf::Clock clock;
	sf::Clock clockFixed;
	sf::Clock clockOut;

	sf::Time time;
	sf::Time timeFixed;
	sf::Time timeOut;

	sf::Color currentColor = sf::Color::Green;
	sf::Color wantedColor = sf::Color::Green;

	int random = 1;
	bool lost = false;
	bool changed = false;

	std::ostringstream ss;
	std::ostringstream sss;

    while (window.isOpen())
    {
        sf::Event event;
		
        while (window.pollEvent(event))
        {
            if (event.type == sf::Event::Closed)
                window.close();
        }

		if(sf::Keyboard::isKeyPressed(sf::Keyboard::Escape))
			window.close();

		time = clock.getElapsedTime();
		timeFixed = clockFixed.getElapsedTime();
		
		if(time.asSeconds() > diff)
		{
			if(currentColor != wantedColor)
			{
				text.setString("You lost!");
				shape.setScale(0.f, 0.f);
				lost = true;
			}
			changed = false;
			random = rand() % 3 + 1;
			clock.restart();
		}

		if(!lost)
		{
			switch(random)
			{
			case 1:
				text.setString("Green");
				shape.setOutlineColor(sf::Color::Green);
				wantedColor = sf::Color::Green;
				break;
			case 2:
				text.setString("Blue");
				shape.setOutlineColor(sf::Color::Blue);
				wantedColor = sf::Color::Blue;
				break;
			case 3:
				text.setString("Red");
				shape.setOutlineColor(sf::Color::Red);
				wantedColor = sf::Color::Red;
				break;
			default:
				std::cout << "Something went wrong with the random number!" << std::endl;
				break;
			}
			
			if(!changed)
			{
				if(sf::Keyboard::isKeyPressed(sf::Keyboard::B))
				{
					shape.setFillColor(sf::Color::Blue);
					changed = true;
				}
				if(sf::Keyboard::isKeyPressed(sf::Keyboard::G))
				{
					shape.setFillColor(sf::Color::Green);
					changed = true;
				}
				if(sf::Keyboard::isKeyPressed(sf::Keyboard::R))
				{
					shape.setFillColor(sf::Color::Red);
					changed = true;
				}
			}

			currentColor = shape.getFillColor();

			scoreText = timeFixed.asSeconds();
			
			ss.clear();
			ss << "Score: " << scoreText;
			
			score.setString(ss.str());
		}
		else
		{
			if(sf::Keyboard::isKeyPressed(sf::Keyboard::Return))
			{
				clockFixed.restart();
				clock.restart();
				random = 1;
				shape.setFillColor(sf::Color::Green);
				shape.setOutlineColor(sf::Color::Green);
				shape.setScale(1.f, 1.f);
				lost = false;
			}
		}

		sss.clear();
		sss << "Difficulty: " << diff;

		diffText.setString(sss.str());

		timeOut = clockOut.getElapsedTime();
		if(sf::Keyboard::isKeyPressed(sf::Keyboard::Left) && timeOut.asSeconds() > 1 && diff > .5)
		{
			diff = diff - .5;
			clockOut.restart();
		}
		if(sf::Keyboard::isKeyPressed(sf::Keyboard::Right) && timeOut.asSeconds() > 1 && diff < 2)
		{
			diff = diff + .5;
			clockOut.restart();
		}

        window.clear();

		window.draw(end);
		window.draw(changeDiff);
		window.draw(exit);
		window.draw(shape);
		window.draw(text);
		window.draw(score);
		window.draw(diffText);

        window.display();
    }
	
    return 0;
}


Thanks in advance!
std::ostringstream::clear only clears the error state of the stream. It doesn't clear out anything that was previously in the stream.

To do that, use std::ostringstream::str with an empty string:

1
2
    sss.clear() ;
    sss.str("") ;
Thank you! That solved it.

If anyone has any constructive criticism it's more than welcome!
Topic archived. No new replies allowed.