Adventure Game Studio

AGS Support => Advanced Technical Forum => Topic started by: Sam. on Sun 30/01/2005 14:11:02

Title: LabelGUI display function results (SOLVED)
Post by: Sam. on Sun 30/01/2005 14:11:02
I have a code that returns an integer value. Unfortunatley i want this to be displayed on a gui. the only way i could think was a GUI label and use the setlabeltext function. unfortunatley it oes not accept integer values. is there a way to put an integer value onto a gui?

EDIT: See my last post
Title: Re: Integers to String
Post by: Rui 'Trovatore' Pires on Sun 30/01/2005 14:14:09
string quickie;
StrFormat(quickie, "%d", integervalue);
lblGUILabel.SetText(quickie);

(if you don't have the beta, replace that last line with the one that is actually used)

BTW, I'm sure this is in the manual. Look in the entry for converting STRING TO INT.
Title: Re: Integers to String
Post by: Sam. on Sun 30/01/2005 14:18:42
you win. it IS in the manual, i didn't look hard enough. cheers.
Title: Re: Integers to String
Post by: Rui 'Trovatore' Pires on Sun 30/01/2005 14:21:00
Heh. Didn't mean to sound like a bully or like a competitor. ;)
Title: Re: Integers to String
Post by: Sam. on Sun 30/01/2005 15:03:08
This was supposed to be a secret but it just won't work. I want a label on my gui which diplays the roman numerals of an integer. Below are my funcitons for this code. How can i get what these return to display in a gui label as a string?

// In local script where you want to print the numerals or in the script setting the label (for the label you should probably use a string that would store the whole number and set that as the label).

/*
** Print numbers fron 1 to 25 as Roman numerals.
*/

Ã,  Ã,  Ã,  Ã,  int x = 1;
Ã,  Ã,  Ã,  Ã,  Display("This program prints out Roman Numerals.");
Ã,  Ã,  Ã,  Ã,  while (x <= 25)Ã,  {
Ã,  Ã,  Ã,  Ã,  Ã,  Ã,  Ã,  Ã,  roman (x);
Ã,  Ã,  Ã,  Ã,  Ã,  Ã,  Ã,  Ã,  x = x + 1 ;
Ã,  Ã,  Ã,  Ã,  Ã,  Ã,  Ã,  Ã,  }
Ã,  Ã,  Ã,  Ã,  Display("I hope you liked it!");
// In global script

/*
** Display the character c as many times as there are
** j's in the number i, then return i minus the j's
*/
function romanize (int i,int j,char c) {

Ã,  Ã,  Ã,  Ã,  while (i>=j)
Ã,  Ã,  Ã,  Ã,  Ã,  Ã,  Ã,  Ã,  {
Ã,  Ã,  Ã,  Ã,  Ã,  Ã,  Ã,  Ã,  Display("%c", c);
Ã,  Ã,  Ã,  Ã,  Ã,  Ã,  Ã,  Ã,  i = i - j;
Ã,  Ã,  Ã,  Ã,  Ã,  Ã,  Ã,  Ã,  }
Ã,  Ã,  Ã,  Ã,  return i;
}


// In global script

/*
** Print an Arabic number in Roman numerals.
*/
function roman (int number) {
int arabic = number;
Ã,  Ã,  Ã,  Ã,  {
Ã,  Ã,  Ã,  Ã,  arabic = romanize(arabic,1000,'m');
Ã,  Ã,  Ã,  Ã,  arabic = romanize(arabic,500,'d');
Ã,  Ã,  Ã,  Ã,  arabic = romanize(arabic,100,'c');
Ã,  Ã,  Ã,  Ã,  arabic = romanize(arabic,50,'l');
Ã,  Ã,  Ã,  Ã,  arabic = romanize(arabic,10,'x');
Ã,  Ã,  Ã,  Ã,  arabic = romanize(arabic,5,'v');
Ã,  Ã,  Ã,  Ã,  arabic = romanize(arabic,1,'i');
Ã,  Ã,  Ã,  Ã,  romanize(arabic,1,'i');
Ã,  Ã,  Ã,  Ã,  Display(" ");
Ã,  Ã,  Ã,  Ã,  }

// In global script

/*
** Display the character c as many times as there are
** j's in the number i, then return i minus the j's
*/
function romanize (int i,int j,char c) {

Ã,  Ã,  Ã,  Ã,  while (i>=j)
Ã,  Ã,  Ã,  Ã,  Ã,  Ã,  Ã,  Ã,  {
Ã,  Ã,  Ã,  Ã,  Ã,  Ã,  Ã,  Ã,  Display("%c", c);
Ã,  Ã,  Ã,  Ã,  Ã,  Ã,  Ã,  Ã,  i = i - j;
Ã,  Ã,  Ã,  Ã,  Ã,  Ã,  Ã,  Ã,  }
Ã,  Ã,  Ã,  Ã,  return i;
}

// In script header (of you want to use the functions in local scripts, or for convenience:

import function romanize (int i,int j,char c);
import function roman (int number);
Title: Re: LabelGUI display function results.
Post by: Pumaman on Sun 30/01/2005 15:12:47
Well, there seems to be something funny with your braces for a start. What exactly is the problem you're having?
Title: Re: LabelGUI display function results.
Post by: Sam. on Sun 30/01/2005 15:18:34
basically, I found a C code to convert arabic numbers to roman numerals, i asked ginny to convert it to AGS script, she cam back with this. I then HAve an integer variable called MyScore. I the want to set a gui label to MYScroe as roman so i call

SetLabelText(8,2, roman(Myscore));

but i get an error message telling em there is a type mismatch so i use the strformat to change it to a string.

StrFormat(BUffer,"%d", Myscore));
SetLabelText(8,2,roman (Buffer));

Still no joy. i get the same mismatch error
Title: Re: LabelGUI display function results.
Post by: Pumaman on Sun 30/01/2005 15:50:05
StrFormat(BUffer,"%d", roman(Myscore));
SetLabelText(8,2,Buffer);

is what you want
Title: Re: LabelGUI display function results.
Post by: Takara on Sun 30/01/2005 15:50:51
I have to admit I haven't looked at your code, but if you check out this thread: http://www.adventuregamestudio.co.uk/yabb/index.php?topic=18915.0 then I made some functions yesterday which convert the current score into a roman numeral.

Takara.
Title: Re: LabelGUI display function results.
Post by: Sam. on Sun 30/01/2005 18:16:23
sorry Takara, i didn't read what your code did but now i understand and it works great. thanks very much.