Adventure Game Studio

AGS Support => Beginners' Technical Questions => Topic started by: suicidal pencil on Mon 16/03/2009 20:18:29

Title: variables in strings. F1 has been no help
Post by: suicidal pencil on Mon 16/03/2009 20:18:29
gah.

On one of the many GUIs in my game, only one has text that has a variable in it. The text in question is supposed to show an integer value, but I can't even get it to compile. Even copy/pasting from the Help comes up with this error:

GlobalScript.asc(118): Error (line 118): Parse error in expr near '"Cash: %d"'

Here's the code:


  //set the cash monitor to the current amount of cash on hand
  ShopGuiCashMonitor.Text = ("Cash: %d", Cash);
  //display the now correctly formatted shop GUI
  ShopGuiBuy.Clickable = false; // The buy button is not visible, since nothing has been selected.
  Shop.Visible = true;


ShopGuiCashMonitor is a label. It works perfectly until I try to toss a variable at it.
Title: Re: variables in strings. F1 has been no help
Post by: GarageGothic on Mon 16/03/2009 20:48:58
Use String.Format, like this:

ShopGuiCashMonitor.Text = String.Format("Cash: %d", Cash);
Title: Re: variables in strings. F1 has been no help
Post by: RickJ on Mon 16/03/2009 20:49:02
Try using: ShopGuiCashMonitor.Text = String.Format("Cash: %d", Cash);

[edit]
hehe, 4 seconds too late ... 
Title: Re: variables in strings. F1 has been no help
Post by: suicidal pencil on Mon 16/03/2009 21:10:44
Thanks!

Works perfectly now. I didn't realize that I had to do that  :P