Editing GUI labels (adding and subtracting numbers from in-game)

Started by aussie, Mon 26/09/2011 15:29:52

Previous topic - Next topic

aussie

Hi all.

I'm still coming to grips with the new editor. I have a question as to how to make a numerical GUI label which I can change as the player does stuff. It's supposed to work similarly to the score function.

In essence, the screen shows a grid with multiple places where the player can drill a well. Drilling a well costs money. The amount of money the player has is displayed inside a GUI window. This amount should decrease everytime he drills a well.

Everything is fine Global Variable-Wise. I set an int variable "money" with an initial value of 1000. Then, every time the player clicks on a hotspot there is a money=money-100 which substracts the money. I can also display it on screen momentarily using the display command.

What I cannot do for the life of me is access the GUI label to display the figure permanently. I thought you could do this with setlabeltext type functions in the old editor. In fact, I think I managed to do it back in the old days. However, I can't really remember and the help html seems a little limited in this regard (either that, or I'm not finding exactly what I'm after).

How would you guys go about it?

It's not the size of the dog in the fight. It's the size of the fight in the dog.

http://www.freewebs.com/aussiesoft/

Khris

The .Text member of a label is in String format, so to subtract from that you'd have to convert the String to an int, subtract, then convert back to a String.

It's much more convenient to store the amount of money in a global variable and update the label text each time it changes.

Open the Global variables pane and create an int, name "player_money", initial value 1000 or whatever the player starts out with.

Then use a function that'll change the value and update the label:

Code: ags
bool ChangePlayerMoney(int amount) {

  if (player_money + amount < 0) return false;

  player_money += amount;
  lblMoney.Text = String.Format("Total money: $%d", player_money);
  return true;
}


Now you can do this:

Code: ags
  // player chose to drill
  if (ChangePlayerMoney(-100)) {
    // drill hole, etc.
  }
  else Display("You can't afford that!");

aussie

It's not the size of the dog in the fight. It's the size of the fight in the dog.

http://www.freewebs.com/aussiesoft/

SMF spam blocked by CleanTalk