• Advertisement
Sign in to follow this  

Outputting an Integer and Manipulating it.

This topic is 2198 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Advertisement
Try replacing the line
SDL_Surface* output = TTF_RenderText_Solid(font, creditString.c_str(), textColor);
with
SDL_Surface* output = TTF_RenderText_Solid(font, ss.str().c_str(), textColor);

Share this post


Link to post
Share on other sites
Okay now its showing on the screen, now if I manipulate would I add 500 to score. Because I'm doing that and it won't work.

Share this post


Link to post
Share on other sites
You need to come up with better problem descriptions that "it won't work". Posting code is generally good, because it completely describes what you are actually doing (though not what you have tried, and what your intent was, which are important too).

Share this post


Link to post
Share on other sites
Assassian, what is your programming experience prior to attempting to make this "lottery" game? It seems like you have little to 0 experience programming, I would suggest going over some of the beginning tutorial for C++, and make some simple programs. You need to crawl before you can walk.

Share this post


Link to post
Share on other sites
Yea..


std::stringstream ss;
ss << score;
std::string creditString = creditString.c_str();

score + 5;


output = TTF_RenderText_Solid(font, ss.str().c_str(), textColor);

apply_surface(0, 0, background, screen);
//apply surfaces
apply_surface( 0, 0, output, screen );


//Update screen
if ( SDL_Flip (screen) == -1 )
{
return 1;
}

//while quit is false
while ( quit == false)
{
//while there event to handle
while ( SDL_PollEvent ( &event ))
{
//if the user hasn't quit
if ( event.type == SDL_QUIT )
{
//if the user hasnt Xed
quit = true;
}

score + 5;
apply_surface(0, 150, output, screen);
//Update screen
if ( SDL_Flip (screen) == -1 )
{
return 1;
}

}
}

Share this post


Link to post
Share on other sites
the line score + 5; accomplishes nothing of use. The first problem with it is that it adds score and 5 but it doesn't do anything with that value so consequently it is lost. Then, even if it was saved, you should put it before you convert score to a string, otherwise you won't see any results until the next time you redraw.

Share this post


Link to post
Share on other sites
I made two functions
first one.



int scoreAdd()
{
int x;
x = score;
x + 5;
return x;
}


second


void integerString()
{
std::stringstream ss;
ss << score;
std::string creditString = creditString.c_str();

output = TTF_RenderText_Solid(font, ss.str().c_str(), textColor);
}


still doesn't work

Share this post


Link to post
Share on other sites
again, lines like x + 5; or score + 5; don't do anything. I would strongly suggest you spend more time on your basics. x + 5 takes x and 5 and adds them together. The result is whatever x is plus 5, but where does that value go? Nowhere, it's lost. Nothing happens in scoreAdd(), you might as well put the score variable in its place. If you want to add 5 to score, write this

score += 5;
or
score = score + 5;

That way you add score and 5 and you replace the old score with the new one.

Share this post


Link to post
Share on other sites
what if I add it and the screen go blank, and it says ".exe has stopped working" when I add this line

std::stringstream ss;
ss << credits;
std::string creditString = creditString.c_str();
output = TTF_RenderText_Solid(font, ss.str().c_str(), textColor);

Share this post


Link to post
Share on other sites
You need to slow down and learn the basics because right now you're just hacking code. Read books, watch lectures, follow tutorials and learn to program. Do this whilst using any language but C++.

Share this post


Link to post
Share on other sites
I'm pretty impressed that you got this far, but I'd agree with teutonicus. Perhaps you should try to just make a basic version of this game first. Maybe something purely text-based? Start with an extraordinarily simple program and keep building on it.

Then, when you thoroughly understand that, revisit SDL and a lot of the problems you're having will be obvious to you.

Share this post


Link to post
Share on other sites
Again, agreement with the general consensus that you need to learn to walk before you can run. Step back from graphics for a little bit. Get a good book, and follow all the exercises in it.

There are many skills you'll need when creating complex projects, and these skills are learned in small projects and reinforced by scaling up the difficulty. A good book's exercises will be designed with exactly this kind of difficulty ramping up in mind.

Share this post


Link to post
Share on other sites
I took you guys advice, went back to the basics and I created a slot machine text version :) Here's the link on youtube

appreciate if you guys subscribe and like :D

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement