Thread: printing variables

  1. #1
    Registered User
    Join Date
    Mar 2007
    Posts
    416

    printing variables

    I'm using allegro to make my own version of pong, and I want the score to be kept track everytime it hits the paddle. So I have points++; for keeping track of points, but it won't print in textout_ex. Is there another print/textout function in allegro to print variables? I did not find anything in a search.

    this doesn't work
    Code:
    textout_ex(screen, font, points, 250, 250, makecol(0, 0, 0), makecol(0, 0, 0));

  2. #2
    Registered User
    Join Date
    Mar 2005
    Location
    Juneda
    Posts
    291
    Have you tryed to use as 3rd variable a text variable instead a numeric one?

    Code:
    sprintf(buffer,"%d",points);
    textout_ex(screen, font,buffer...
    Niara

  3. #3
    Registered User
    Join Date
    Mar 2007
    Posts
    416
    that still didnt work. It still ends up saying i need "something" instead of a variable inside textout.

  4. #4
    For Narnia! Sentral's Avatar
    Join Date
    May 2005
    Location
    Narnia
    Posts
    719
    Here's a bright idea, post the exact error message! Instead of having us figure it out.
    Videogame Memories!
    A site dedicated to keeping videogame memories alive!

    http://www.videogamememories.com/
    Share your experiences with us now!

    "We will game forever!"

  5. #5
    Registered User
    Join Date
    Mar 2007
    Posts
    416
    Quote Originally Posted by Sentral View Post
    Here's a bright idea, post the exact error message! Instead of having us figure it out.
    don't have to be a jerk about it, just ask.

    240 C:\Dev-Cpp\Codex\Pong\Pong.cpp invalid conversion from `int' to `const char*'

    240 C:\Dev-Cpp\Codex\Pong\Pong.cpp initializing argument 3 of `void textout_ex(BITMAP*, const FONT*, const char*, int, int, int, int)'

  6. #6
    For Narnia! Sentral's Avatar
    Join Date
    May 2005
    Location
    Narnia
    Posts
    719
    Maybe this: http://www.die.net/doc/linux/man/man3/textout_ex.3.html

    I'm guessing your 'points' is of type int, which cannot be used for the third parameter. The error is basically telling you what to fix.

    PS: Perhaps you should have not been a lazy poster, and you wouldn't have gotten a jerk remark.
    Videogame Memories!
    A site dedicated to keeping videogame memories alive!

    http://www.videogamememories.com/
    Share your experiences with us now!

    "We will game forever!"

  7. #7
    Registered User
    Join Date
    Mar 2007
    Posts
    416
    even if points is changed to a const char* variable it still won't run correctly. Windows will say an error has occured and close the program. I just want to know if there is another function like textout_ex that I can use to display variables, specifically ints/doubles.
    Last edited by scwizzo; 04-06-2007 at 07:55 PM.

  8. #8
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    39,660
    > don't have to be a jerk about it, just ask.
    He shouldn't need to ask, if you'd asked a smart question in the first place.
    http://www.catb.org/~esr/faqs/smart-questions.html
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.

  9. #9
    Registered User
    Join Date
    Mar 2005
    Location
    Juneda
    Posts
    291
    There shouldn't be any problem with the code I posted, I imagine you have something like:

    Code:
    static int points=0;
    function drawpoints(BITMAP screenbuffer)
    {
    char buffer[20];
    sprintf(buffer,"%d",points);
    textout_ex(screenbuffer,font,buffer,250,250,makecol(0,0,0),makecol(0,0,0));
    }
    Because you haven't posted any piece of code I'm assuming that you use doublebuffering for drawing it all, so don't draw the text directly to the 'screen' default bitmap.

    A second thing, read the Allegro documentation, in the function call you posted you are using black text with black background... I think you won't see the points with that color combination.

    If your program still crashes the problem should be from other part, not this one (I suppose).

    Niara

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Best way to avoid using global variables
    By Canadian0469 in forum C++ Programming
    Replies: 7
    Last Post: 12-18-2008, 12:02 PM
  2. Father and Son Variables
    By khdani in forum Linux Programming
    Replies: 3
    Last Post: 11-28-2008, 06:42 PM
  3. Replies: 15
    Last Post: 09-30-2008, 02:12 AM
  4. esbo's data sharing example
    By esbo in forum C Programming
    Replies: 49
    Last Post: 01-08-2008, 11:07 PM
  5. static variables
    By Luigi in forum C++ Programming
    Replies: 4
    Last Post: 04-24-2003, 07:13 PM