Adventure Game Studio

AGS Support => Beginners' Technical Questions => Topic started by: Diji1 on Thu 17/01/2008 15:42:11

Title: Need help displaying stats.
Post by: Diji1 on Thu 17/01/2008 15:42:11
Hey.
I have a problem with displaying my magic points in the GUI.
Here is the code I have -

function repeatedly_execute() {

String magic;
String.Format(magic, "%d", GetGlobalInt(2));
lbla.Text=String.Format(0, 4,  magic));

}

The error message I am given says -
Type Mismatch : cannot convert 'int' to 'const string'

Help a noobie plz?
Title: Re: Need help displaying stats.
Post by: Ubel on Thu 17/01/2008 15:56:39
This is what you'll want to do:


function repeatedly_execute() {
    lbla.Text = String.Format("Magic: %d", GetGlobalInt(2));
}
Title: Re: Need help displaying stats.
Post by: Diji1 on Thu 17/01/2008 17:13:10
thank you so much!
thats sorted the problem out.
Title: Re: Need help displaying stats.
Post by: Radiant on Thu 17/01/2008 19:20:36
Quote from: Diji1 on Thu 17/01/2008 15:42:11
lbla.Text=String.Format(0, 4,  magic));

While the solution has already been given by Pablo, the problem is in the line above. The first and second arguments to String.Format need to be strings, not integers.
Title: Re: Need help displaying stats.
Post by: Khris on Fri 18/01/2008 00:21:09
If by the "0, 4" stuff you wanted to display leading zeros, here's the proper way (with the corrected intermediate step):
function repeatedly_execute() {

  String magic;
  magic = String.Format("%04d", GetGlobalInt(2));
  lbla.Text= magic;

}

But, as was shown, using a variable isn't necessary here.