Author Topic: Printing an int variable onto the screen (Score which is an integer)  (Read 3126 times)

Micboy

  • Jr. Member
  • **
  • Posts: 79
  • Karma: +0/-2
    • View Profile
Hi guys,

For my game, I need to print the score, which is constantly updated.

I have a function called PrintSteps:

Code: [Select]
string Steps;
int Step = 0;
bool StepsInit = false;
int MyFont = FontAdd("Helvetica", "Regular", 12, 0xFFFFFF);

void PrintSteps(int n)//n=number of steps
{
//add text to screen to show how many buttons have been pressed
Steps=n+1;
Steps="new!";
int MyText2;
if(StepsInit==false){
//int MyText1//(char *)Steps.c_str()
MyText2 = TextAdd(100, 50, (char *)Steps.c_str(), MyFont);
}
else TextSetText(MyText2,(char *)Steps.c_str());
StepsInit = true;
}

(in a dif function):
PrintSteps(Step)
   

Basically, how do I output a number onto the screen?

I tried:
Code: [Select]
int Steps;
MyText2 = TextAdd(100, 50, Steps, MyFont);

But that dosent seem to work?

Thank you in advance,

Micboy

ciuffolo

  • Guest
Re: Printing an int variable onto the screen (Score which is an integer)
« Reply #1 on: January 14, 2013, 01:26:21 pm »
I can't believe it, is the same thing that I'm trying to do, any help?

nednones

  • Guest
Re: Printing an int variable onto the screen (Score which is an integer)
« Reply #2 on: January 14, 2013, 01:47:50 pm »
You need to declare a int handle to your text add first in your AppMain(), e.g.

int ScoreHandle;

void AppMain()
{
    ScoreHandle = TextAdd(x, y, "    ", FontHandle);
}

Then in the scores you need to have the sprintf function to convert your integer and use the update text function, e.g.

void PrintSteps(int n)
{
   char Buffer[100];
   sprintf(Buffer, "%d", TheScoreValue);

   TextSetText(ScoreHandle, Buffer);
}

ciuffolo

  • Guest
Re: Printing an int variable onto the screen (Score which is an integer)
« Reply #3 on: January 14, 2013, 02:22:42 pm »
This is the code that I wrote:
Code: [Select]
fh=FontAdd("Arial","Regular",20,0xFF0000);
  th=TextAdd(CentroX-50,320,"punteggio=",fh);
   char Buffer[100];
   sprintf(Buffer, "%d", 10);

   TextSetText(th, Buffer);
But it doesn't show anything.
When i break the program and point on Bueffer i can see this:0x011bee3c "10"
no errors

edit:
Think i only have some problems with Visual Studio, because I can't see anything  also if I write only the two first lines...

reedit:
Yes,now it works,it was me...When i write in y 320 it goes out of the screen, the code that I posted works perfectly (exepted the coordinates),I hope that will help Micboy

« Last Edit: January 14, 2013, 03:24:03 pm by ciuffolo »

Micboy

  • Jr. Member
  • **
  • Posts: 79
  • Karma: +0/-2
    • View Profile
Re: Printing an int variable onto the screen (Score which is an integer)
« Reply #4 on: January 15, 2013, 01:08:25 pm »
Thanks! I will let you know if it works!

ciuffolo

  • Guest
Re: Printing an int variable onto the screen (Score which is an integer)
« Reply #5 on: January 15, 2013, 02:12:20 pm »
Thabks, but i've another question, can i convert char* to int in dragonfire sdk? I tried all the sprtintf letters...

JB

  • Guest
Re: Printing an int variable onto the screen (Score which is an integer)
« Reply #6 on: January 15, 2013, 05:43:42 pm »
Quote
Thabks, but i've another question, can i convert char* to int in dragonfire sdk? I tried all the sprtintf letters...

my understanding of this is you're trying to convert a pointer to an int.  A pointer points to some place in the memory where a variable is held (so why would you want to change the pointer?) - presumably you want to change the value in the memory really?
Maybe an example of what you're trying to do?

ciuffolo

  • Guest
Re: Printing an int variable onto the screen (Score which is an integer)
« Reply #7 on: January 16, 2013, 08:25:45 am »
Oh, i resolved this too with this
Code: [Select]
  int mynumber=atoi(thecharvalue);