I have been looking through some old topics that suggest how to create a health bar and I tried all of the options, but I still cannot make it work. I couldnt find a simple universal way of how to create:
1. a GUI (or gui label) that will display the value of health/skill etc.
2. a script (whether int, string or getglobalint) that is easy to do/use regarding the ADDING OR SUBSTRACTING POINTS from this value of health or skill.
Also I want my character to be able or not to be able to perform some actions, depending on the value of the skill.
Can you help me please?
Thank you!
I assume you have the knowledge of makeing a GUI so here's some simple code.
--------------------------
***In the global script***
--------------------------
//Top of global script
int Health;
export Health;
game_starts {
Health = 100; //Or whatever you want.
}
repeatedly_execute {
lblHealth.Text = String.Format("Your health: %d", Health); //Sets the label lblHealth's text to the current health.
}
---------------------------------
***In the global script header***
---------------------------------
import int Health;
So all you then need to do is write Health = 90 or Health -= 10 to change the health.
The same if it's skill, and then you can always check if the skill is enough.
if (Skill == 10){
Something
}
else Display("You can't do it!");
Thanks a lot. My Gui is now showing a number (finally), but it is showing the wrong number. 46. I dont know why. Here is my script:
// main global script file
int Skill;
export Skill;
#sectionstart game_start // DO NOT EDIT OR REMOVE THIS LINE
function game_start() // called when the game starts, before the first room is loaded
{
Skill = 0;
}
#sectionend game_start // DO NOT EDIT OR REMOVE THIS LINE
#sectionstart repeatedly_execute // DO NOT EDIT OR REMOVE THIS LINE
function repeatedly_execute()
{
// put anything you want to happen every game cycle here
skillpoints.Text = String.Format("%d, Skill");
}
// Main header script - this will be included into every script in
// the game (local and global). Do not place functions here; rather,
// place import definitions and #define names here to be used by all
// scripts.
import int Skill;
Quote from: Gepard on Mon 26/05/2008 20:53:09
Thanks a lot. My Gui is now showing a number (finally), but it is showing the wrong number. 46. I dont know why. Here is my script:
// main global script file
int Skill;
export Skill;
#sectionstart game_start // DO NOT EDIT OR REMOVE THIS LINE
function game_start() // called when the game starts, before the first room is loaded
{
Skill = 0;
}
#sectionend game_start // DO NOT EDIT OR REMOVE THIS LINE
#sectionstart repeatedly_execute // DO NOT EDIT OR REMOVE THIS LINE
function repeatedly_execute()
{
// put anything you want to happen every game cycle here
skillpoints.Text = String.Format("%d", Skill);
}
// Main header script - this will be included into every script in
// the game (local and global). Do not place functions here; rather,
// place import definitions and #define names here to be used by all
// scripts.
import int Skill;
Check the correction and you will find the mistake ;)
Jp
Quote from: Gepard on Mon 26/05/2008 20:53:09
skillpoints.Text = String.Format("%d, Skill");
You've misplaced the second ".
It's
String.Format("%d", Skill);
;D Thanks a lot! All of you. See, this is why AGS is so tricky :) One little ". ;D