SFML Score Set-Up

I want to set up a score, at the minute it is like a 10 digit random number the time works fine the code content is all thats needed below, how would I set it to 0 and implement it into an if function so score++ when collision with enemy happens, thanks!

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


	unsigned int	    _plyr_lives;    //Number of Lives the Player has. 
	unsigned int	    _plyr_score;   //The Current Score

//---------create HUD-------------------------

		this->_text_time.setFont(this->_font_res.get(0));
		this->_text_time.setColor(this->_text_clr);
		this->_text_time.setCharacterSize(26);
	    this->_text_time.setString("Score : ");
	    this->_text_time.setPosition(100,20);

		this->_text_score.setFont(this->_font_res.get(0));
		this->_text_score.setColor(this->_text_clr);
		this->_text_score.setCharacterSize(26);
		this->_text_score.setString("Time : ");
		this->_text_score.setPosition(300,20);





  //----------------------------update score and time -------
	
	s_total += ptpf;

	std::stringstream tss;
	tss << std::fixed;
	tss.precision(1);
	tss << s_total.asSeconds();

this->_text_score.setString("Score: " + sf::toString(this >_plyr_score));

this->_text_time.setString("Time: " + sf::toString(tss.str()));
I want to set up a score, at the minute it is like a 10 digit random number

your score is not initialized, no value has been asigned, so the bits where the memory is located are garbage, short: it has an undefined value
unsigned int _plyr_score = 0; // assigns value, no garbage anymore


how do i [...] implement it into an if function so score++ when collision with enemy happens, thanks!

If you know when a collision happens you can just do it like this:
1
2
if(collisionWithEnemy() == true) 
    score++; 
Last edited on
@Gamer2015 got it working bro, some reason it wouldnt work in the class i moved it now it works! thanks!
good to hear :)

please mark this question as answered (scroll to top and click on the "Mark as ✓")
Topic archived. No new replies allowed.