Jump to content

  • Log In with Google      Sign In   
  • Create Account


Outputting an Integer and Manipulating it.


Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.

  • You cannot reply to this topic
41 replies to this topic

#21 BCullis   Crossbones+   -  Reputation: 1813

Like
0Likes
Like

Posted 10 January 2012 - 11:24 PM

What do you expect this line to do?:
SDL_BlitSurface( creditString, NULL, screen, NULL);

Or more importantly, isn't this throwing an error at you as well? Because when I look at the SDL reference docs, the first argument of SDL_BlitSurface definitely isn't a std::string...
Hazard Pay :: FPS/RTS in SharpDX
DeviantArt :: Because right-brain needs love too

Sponsor:

#22 Assassin7257   Members   -  Reputation: 105

Like
0Likes
Like

Posted 10 January 2012 - 11:39 PM

I wasn't getting an error, I just want to know how would I apply it to the screen now ?

#23 BCullis   Crossbones+   -  Reputation: 1813

Like
0Likes
Like

Posted 10 January 2012 - 11:53 PM

If you've had success blitting other surfaces to the screen, you have everything you need. The key points:
1) Turn an integer into a string using stringstream
2) Turn a string into an SDL Surface* using the TTF function.

So if your code still looks like it did in the last big code post, I'd suggest changing that SDL_BlitSurface call from (creditString, ...) to (output, ...) as creditString is your std::string from before, while output is a pointer to a surface (which is what SDL_BlitSurface expects as its first argument).
Hazard Pay :: FPS/RTS in SharpDX
DeviantArt :: Because right-brain needs love too

#24 Assassin7257   Members   -  Reputation: 105

Like
0Likes
Like

Posted 11 January 2012 - 12:02 AM

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

SDL_Surface* output = TTF_RenderText_Solid(font, creditString.c_str(), textColor);
SDL_BlitSurface (output, NULL, screen, NULL);

apply_surface(150, 150, output, screen);

This is what is looks like and nothing is showing.

#25 RulerOfNothing   Members   -  Reputation: 1160

Like
1Likes
Like

Posted 11 January 2012 - 12:05 AM

One question, are you blitting the text to the screen before or after you blit the background image to the screen?

#26 Assassin7257   Members   -  Reputation: 105

Like
0Likes
Like

Posted 11 January 2012 - 12:06 AM

Before I did it before, now I did after and now random characters show on the screen.

#27 Assassin7257   Members   -  Reputation: 105

Like
0Likes
Like

Posted 11 January 2012 - 12:08 AM

like Ua]ew

#28 RulerOfNothing   Members   -  Reputation: 1160

Like
0Likes
Like

Posted 11 January 2012 - 12:18 AM

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);

#29 Assassin7257   Members   -  Reputation: 105

Like
0Likes
Like

Posted 11 January 2012 - 07:17 AM

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.

#30 rip-off   Moderators   -  Reputation: 8166

Like
0Likes
Like

Posted 11 January 2012 - 08:59 AM

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).

#31 BeerNutts   Crossbones+   -  Reputation: 2860

Like
0Likes
Like

Posted 11 January 2012 - 12:51 PM

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.
My Gamedev Journal: 2D Game Making, the Easy Way

---(Old Blog, still has good info): 2dGameMaking
-----
"No one ever posts on that message board; it's too crowded." - Yoga Berra (sorta)

#32 Assassin7257   Members   -  Reputation: 105

Like
0Likes
Like

Posted 11 January 2012 - 06:25 PM

Progamming for like a month, just using SDL for the first time

#33 RulerOfNothing   Members   -  Reputation: 1160

Like
0Likes
Like

Posted 11 January 2012 - 06:34 PM

Are you redrawing the surface with the text on it when you change the score? I have managed to forget to do this a few times.

#34 Assassin7257   Members   -  Reputation: 105

Like
0Likes
Like

Posted 11 January 2012 - 06:49 PM

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;
        }

        }
    }


#35 boogyman19946   Members   -  Reputation: 1056

Like
0Likes
Like

Posted 11 January 2012 - 06:56 PM

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.
"If highly skilled generalists are rare, though, then highly skilled innovators are priceless." - ApochPiQ

My personal links :)
- Khan Academy - For all your math needs
- Java API Documentation - For all your Java info needs :D
- C++ Standard Library Reference - For some of your C++ needs ^.^

#36 Assassin7257   Members   -  Reputation: 105

Like
0Likes
Like

Posted 11 January 2012 - 07:11 PM

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

#37 boogyman19946   Members   -  Reputation: 1056

Like
0Likes
Like

Posted 11 January 2012 - 07:21 PM

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.
"If highly skilled generalists are rare, though, then highly skilled innovators are priceless." - ApochPiQ

My personal links :)
- Khan Academy - For all your math needs
- Java API Documentation - For all your Java info needs :D
- C++ Standard Library Reference - For some of your C++ needs ^.^

#38 Assassin7257   Members   -  Reputation: 105

Like
0Likes
Like

Posted 11 January 2012 - 09:26 PM

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);

#39 teutonicus   Members   -  Reputation: 518

Like
2Likes
Like

Posted 11 January 2012 - 10:00 PM

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++.

#40 Slavik81   Members   -  Reputation: 360

Like
0Likes
Like

Posted 11 January 2012 - 11:31 PM

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.




Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.



PARTNERS