Solved: Wanting to make a status screen for the character's attributes

Started by johanvepa, Sat 27/04/2013 22:53:26

Previous topic - Next topic

johanvepa

I think I got the hang of global integers now, but I need to confer upon the player the means of keeping track of certain essential values. I need a status screen, in other words, and I think I should do it as a GUI.
(not that it has to be a GUI, but I believe thats the best way to go?)

I would like to have some global variables shown in a simple manner. Nothing fancy, just like for example:

Attributes:
Strength 12
Dexterity 18
Wits 8

Status:
Health 2 / 15
Magical energy 30 / 65

Basic needs:
You are hungry
You are sleep-deprived

And perhaps a picture or two to top things off. I want to simply allow the player to push a button, which displays this GUI (and pauses the game). On clicking the GUI the game unpauses and the GUI becomes invisible again. I've tried using the standard buttons to come up with something but it seems to be harder than it, well, harder than it seems.

This should be such a simple task, yes? But I can't see the forest for the woods.

Khris

Since the GUI isn't displayed all the time, the values need to be updated only right before the GUI is shown.

Create a label for each value and name them accordingly.
In the "Show Status" button's OnClick function, do this:
Code: ags
  lblStrength.Text = String.Format("Strength: %d", player_strength);
  lblDexterity.Text = String.Format("Dexterity: %d", player_dexterity);
  ...
  lblHealth.Text = String.Format("Health: %d / %d", current_health, max_health);
  ...
  gStatus.Visible = true;

johanvepa

Khris, are you some kind of wizard?

Anyway, I tried it out, and can report that it works. And thank you very much for being there to save the day. The strength score now is displayed in the lblSTRENGTH label in the character status GUI when I press the "show status screen" button in the generic status bar GUI.
(And the strength attribute working as an int may come in handy for saving little old ladies from robbers and such. )

Two questions:
Is it possible to simplify the relation between the strength value integer and the strength label further?
I am thinking something like using the label as an int rather than as a textual display of the value of an int. If I can make the lblSTRENGTH have a value in numbers, rather than being a piece of text, which I must then format to show the value of an int, I could use it as an int in and of itself. Simply put, first question: Can I use a label as an integer?


Second question, being ambitious, I decided also to have a name tag label.
In the character status screen GUI, I therefore also put a label called lblNAME.

I use this in my globalscript.asc:
Code: AGS

String NAME;
export NAME;


and this in my globalscript.ash:
Code: AGS

import String NAME;


now, at the beginning of the game, at the first room load of the first room, I put this (amongst others):
Code: AGS

NAME = Game.InputBox("So what's your name, fella?");
lblNAME.Text = NAME;


And it works! When I press the status screen button, the NAME appears at the lblNAME label. And stays there.

Now, when someone is talking to cEgo, I would like them to greet him, saying something like "Hello there Wilbur, what are you doing here in this rainy weather?". So I tried with this in the room script:

Code: AGS

Display(String.Format("have a nice day, %d", NAME));


Alas, here my luck ends. Instead of the NAME, a string of numbers is displayed.

I'm pretty certain there must be a completely straightforward solution to this??

Crimson Wizard

1. No, you cannot use Label as integer directly, but I guess you could simplify things for yourself by writing two extender functions that would "convert" integer to string and back.
On extender functions: http://www.adventuregamestudio.co.uk/wiki/Extender_functions
Example:
Code: ags

function SetInt(this Label *, int value)
{
   this.Text = String.Format("%d", value);
}

int GetInt(this Label *)
{
   return this.Text.AsInt;
}


Usage:
Code: ags

lblMyLabel.SetInt(10);

int a = lblMyLabel.GetInt();



2. You are using wrong format modifier, %d is for numbers, %s is for text. More information on formatting may be found in manual:
http://www.adventuregamestudio.co.uk/wiki/String_formatting_(manual)

johanvepa

Thank you very much, both of you. Things are working out just fine here   :)

And I found the proper place in the manual, too.

Never gt around to setting integers as string and vice versa, but found out I didn't need to, as long as I stick to integers and labels in the GUI.

SMF spam blocked by CleanTalk