variables in strings. F1 has been no help

Started by suicidal pencil, Mon 16/03/2009 20:18:29

Previous topic - Next topic

suicidal pencil

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:

Code: ags

  //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.

GarageGothic

Use String.Format, like this:

Code: ags
ShopGuiCashMonitor.Text = String.Format("Cash: %d", Cash);

RickJ

Try using: ShopGuiCashMonitor.Text = String.Format("Cash: %d", Cash);

[edit]
hehe, 4 seconds too late ... 

suicidal pencil

Thanks!

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

SMF spam blocked by CleanTalk