Adventure Game Studio

AGS Support => Beginners' Technical Questions => Topic started by: FanOfHumor on Wed 19/01/2022 16:00:58

Title: (Solved)How to use a float in a label
Post by: FanOfHumor on Wed 19/01/2022 16:00:58
I need to put an integer into a label.text.I converted the integer to float but I cant seem to convert float to string.
Label4.Text=IntToFloat(player.x);
What is wrong with this?
In fact I cant seem to put anything other than string in labels. Yet I can put integers and others into player.say.
Title: Re: How to use a float in a label
Post by: eri0o on Wed 19/01/2022 16:12:07
You need to use String.Format to create strings that parse these.

https://adventuregamestudio.github.io/ags-manual/String.html#stringformat

More information on formatting is here

https://adventuregamestudio.github.io/ags-manual/StringFormats.html
Title: Re: How to use a float in a label
Post by: Khris on Wed 19/01/2022 16:30:15
Exactly, for instance like this:

Code (ags) Select
  Label4.Text = String.Format("player x is %d", player.x);

Conversion to float is pointless here; you can insert an integer into a string as well.
Title: Re: How to use a float in a label
Post by: FanOfHumor on Wed 19/01/2022 17:19:43
Thanks for the help.