I am assuming this post belongs in the ‘Beginners Technical Questions' area because I felt it was not a concept that should be terribly complex.
I'm having some difficulty in figuring out how to successfully use global variables in my game, so I devised an exercise that would allow me to learn a specific application for them. In general, this should help me personally learn the in and outs of using global variables as well as some other basic functions that I am not yet familiar with. I have read through the AGS manual in detail and am comfortable with the very basics of using scripting as well as how to use the commands. I am using AGS v2.70. I don't usually enjoy asking questions on Internet forums because of how inept it makes one look, but here we go.
The concept we're trying to accomplish is this. I think it's a useful idea for an adventure game. My profound apologies if it has been done before and I've been too unintuitive to look for a tutorial somewhere that explains how to do it. If anybody would be willing to take the time to read through the list of things I want to do below and offer some assistance with any of them I would be extremely grateful.
1) The player has a health meter constantly visible on the screen.
I assumed that this would be easily accomplished with a GUI that displays the image of my little meter. I am entirely clueless on how to do this.
2) The player's health meter is initially full.
I've begun by declaring int health = 20; at the top of my global script in the AGS editor, before any functions, just as the manual stated.
3) When the variable health is decreased by 1, the health meter graphic is changed to reflect this.
I've already constructed an animation of this meter I want in paint, and I assumed that I'd be using a view or separate graphics in the sprite editor to accomplish this. I don't need an explanation of how to import my graphics. The actual problem is what I do to make my health meter changed. I thought this was related to using the command if health = WHATEVER { } with of course what I do to change the image put into the braces.
Addition: After I posted I realized that perhaps using a GUI button or label with my different health meter images might be a good idea. You can change the background of those items, yes?
4) The variable health can be changed from any room script in my game.
I hope I understand correctly that a global variable cannot be changed from any room in the game unless it is exported for the game script to use it elsewhere. I would like to know where I am to use the command export health. The manual says at the end of your global script, but is this to be outside all of the functions as with declaring a variable in the first place?
Thank you so very much for your anticipated responses. I look forward to reading them.
- SteveÃ, ??? <- OMG CLUELEZ N00B
There are various ways you can do this.
One would be to create a GUI with a button on it, and set the button to your health meter image. Then, you adjust the width of the button depending on the player's health, so that the right hand side of the image gradually gets cut off.
Perhaps an easy way to start off would just be to add a GUI Slider, and adjust its Value depending on the player's health.
So if you add a Slider, set Min to 0 and Max to 20, and then just do something like this after the player's helath changes:
sldHealth.Value = health;
it should give you a start.