Adventure Game Studio

AGS Support => Beginners' Technical Questions => Topic started by: on Tue 08/07/2003 21:30:29

Title: Convesion
Post by: on Tue 08/07/2003 21:30:29
Is there an easy way to cast an integer as a string.  I noticed that casting isn't allowed.  I want to read a keyboard code and save it as the corresponding letter as a string.  I don't want to have to write a function

if (keycode == 65)
 str = "A";
else if...

I couldn't find anyting in the help file or searching this forum so I think I already know the answer but if anyone else knows a shortcut I would be happy to hear it.

Steve O.
Title: Re:Convesion
Post by: Proskrito on Tue 08/07/2003 21:45:04
i think StrFormat("%d",integer) would do that
Title: Re:Convesion
Post by: on Wed 09/07/2003 00:25:53
I tried that, it just put the number into the string instead of the letter.
Title: Re:Convesion
Post by: Proskrito on Wed 09/07/2003 01:00:00
I just readed the first line, sorry.
QuoteIs there an easy way to cast an integer as a string.
Then the only thing i can think of is using StrSetCharAt, maybe:
function CharToString(string letter, char keycode){//you can use an int here instead of a char i think
StrCopy(letter,"x");
StrSetCharAt(letter,0,keycode);
}

But there must be another neater way to do it, which somebody will tell you  ;) (im not sure even if that way would work)
Title: Re:Convesion
Post by: Scorpiorus on Wed 09/07/2003 21:14:10
Yep, Proskrito has the right idea.

Also the same using StrFormat:

string letter;
StrFormat(letter, "%c", keycode);


or for adding a sequence of codes:

StrFormat(letter, "%s%c", letter, keycode);

-Cheers