Author Topic: Editing GUI labels (adding and subtracting numbers from in-game)  (Read 154 times)  Share 

aussie

  • Act like you know.
  • aussie worked on a game that was nominated for an AGS Award!
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?

« Last Edit: 26 Sep 2011, 16:15 by 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/

Khris

  • Evil Dark Emperor Death-Kill
    • Lifetime Achievement Award Winner
    •  
    • I can help with play testing
    •  
    • I can help with scripting
    •  
    • I can help with translating
    •  
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]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;
}[/code]

Now you can do this:

[code]  // player chose to drill
  if (ChangePlayerMoney(-100)) {
    // drill hole, etc.
  }
  else Display("You can't afford that!");[/code]
http://whathaveyoutried.com/

The other day on yahoo answers:
"Can you print colored images with black ink? If so tell me how please Thanx Kimberly"

aussie

  • Act like you know.
  • aussie worked on a game that was nominated for an AGS Award!
That worked well. Thanks! :D


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/