Jump to content
  • Advertisement
Sign in to follow this  
chrpeter

Beginner Allegro Question

This topic is 3644 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

How do I print out a variable along with a message in Allegro? int a = 0; For example Score: a I have the score part but I cant seem to get the variable next to it. In C++ I would do cout << "Score: " << a << endl; Here is what I have so far: textprintf_ex(screen, font, (SCREEN_W-SCREEN_W + 10), (SCREEN_H-SCREEN_H+10), color, 0, "Score: ", SCREEN_W, SCREEN_H); //this prints out Score: but without the variable next to it. Thanks.

Share this post


Link to post
Share on other sites
Advertisement
Quote:

textprintf_ex(screen, font, (SCREEN_W-SCREEN_W + 10), (SCREEN_H-SCREEN_H+10), color, 0, "Score: ", SCREEN_W, SCREEN_H);


Evaluates to:
textprintf_ex(screen, font, 10, 10, color, 0, "Score: ");

I'm not sure if you know that this probably doesn't do what you think it will do. :| The SCREEN_W and SCREEN_H parameters at the end of the function are actually formatted into your "Score: " string. (But since you don't specify the formatting string to expect any variables, it doesn't print them). [smile] If you were to change "Score: " to "Screen dimensions: %i wide by %i tall" then you'll see something like "Screen dimensions: 800 wide by 600 tall" appear on the screen. See the Format Specification Fields to browse what you can do with printf. Also view the sample code at the bottom of the page to see samples of printf in action.

What you probably meant was:

textprintf_ex( screen, font, 10, 10, color, 0, "score: %i", score );





You also mentioned on how you would do it using std::cout.
Here's how you would use it using C++ string streams (similar to using std::cout):

#include <sstream> // for string streams

std::stringstream ss;
ss << "score: " << score; // similar to using cout

textout_ex( screen, font, 10, 10, ss.str().c_str(), color, 0 ); // use the stringstream





Anyways, hope this helps. [lol]

[Edited by - _fastcall on October 26, 2008 11:09:01 PM]

Share this post


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

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!