Page 2 of 3

GMGE

PostPosted: Sat Aug 27, 2005 8:11 am
by diduknow
You can make a healthbar in one line of code in GM

Re: GMGE

PostPosted: Sat Aug 27, 2005 9:14 am
by Joshua Worth
diduknow wrote:You can make a healthbar in one line of code in GM
Quit it about GM. And besides, GE looks nicer, and uses a extremely good programming language called C, and it is obviously much better than whatever :cry: GM :cry: uses!

PostPosted: Sat Aug 27, 2005 9:56 am
by diduknow
the scripting language GM uses is very very close to C, same syntax. but you dont have to write miles of code to make a healthbar.
Game Editor implements a C-like script language

that is from the documentation. so i guess the script isnt quite C now, is it?

PostPosted: Sat Aug 27, 2005 11:01 am
by ondy1985
GE's scripting language is very very similar to the C syntax too. One could say they are almost identical, except for minor differencies. I have both GE and GM installed on my computer. Both tools are great and I admire their creators. But I would probably never use either of them to create Win32 game, because I like to do my own game engines in DirectX 9.0 with Visual C++. I don't know anything about creating games for PocketPC. And that's where it comes to GE as it can export games for PocketPC as well. PocketPC market is growing fast and GE is the easiest way to 'jump in'.

I bet all GE users know about GM but they decided to use GE for some reason. I wonder how many GM users know GE and still use GM...

PostPosted: Sat Aug 27, 2005 11:04 am
by Joshua Worth
Replacement

PostPosted: Sat Aug 27, 2005 11:33 am
by Game A Gogo
Joshua Worth wrote:Your signature should say "GERULES GMSUX". And this forum is for game editor only, so get out!

you said it man :wink:

PostPosted: Wed Jan 25, 2006 10:06 pm
by bkelynch
I gotta problem here...when I typed in the code in script editor, and clicked on immediete action, an error window came up with this in it:

error

Error line 2: Illegal function definition in ex371229927689
Error line 17: Undeclared Identifier UpdateHealthBar
Error line 24: Undeclared Identifier UpdateHealthBar
Error line 26: Expected ;

I copied the code you had written and pasted it onto script editor, so it is exactly the same as the code you had posted.

PostPosted: Wed Jan 25, 2006 11:45 pm
by makslane
You need put this functions in the Global Code editor

PostPosted: Thu Jan 26, 2006 10:40 am
by Diana Kennedy
Game a Gogo wrote:
Joshua Worth wrote:Your signature should say "GERULES GMSUX". And this forum is for game editor only, so get out!

you said it man :wink:


Yup: I don't think it is very respectful to carry ones like for the concurrent in this forum.

PostPosted: Thu Jan 26, 2006 8:39 pm
by Game A Gogo
now, im a change man, and i know every corner of GM, and its pretty good, but i tink GE is way better, for me eventully.

PostPosted: Thu Apr 20, 2006 4:06 am
by next2sin
how would you make the health bar change when it actor collides with another actor?

PostPosted: Thu Apr 20, 2006 4:20 am
by DilloDude
Use
Code: Select all
ChangeHealth(-5);
(or whatever value you want)
on collision.

Re: Making a Health Bar - Tutorial

PostPosted: Thu Mar 01, 2007 12:26 am
by DarkParadox
ondy1985 wrote:The idea
I found several threads here discussing health bars (or health meters, call it whatever you want) with no satysfying answers on how to do this, so here is my answer.
The aim is to create a bar that will reflect the players health, ammunition or whatever you want, and not have dozens of actors to do that. I'm going to introduce the way I used in my upcoming space shooting game.

1)
It may sound a bit strange, but we will use one text actor for this. First, we need a bitmap "font" that will make the health bar.
Like this one that I have created: Image

2)
Now we have to create the actor in GE. Let's name it "health_bar". Don't add any animations. Click on the Text button in Actor Properties. Now click the New Font button. We find the file with our "font" and set it's properties. The initial character will be 0 and the number of characters is 3. You can write some text into the actor (but remember to use only 0, 1 and 2 characters) to see if it works fine.

3)
Now we need the bar to reflect the player's health. Create "g_PlayerHealth" variable in 'Variables' and make it Global Integer. We will write som simple functions in 'Global Code' to easily change the g_PlayerHealth value and show it via the health bar at the same time.

Code: Select all
void UpdateHealthBar()
{
    int i;
    strcpy(health_bar.text,"");
    for (i=0; i<g_PlayerHealth; i++)
        {
            if (i<=5) strcat(health_bar.text, "0");
            if ((i>5)&&(i<=15)) strcat(health_bar.text, "1");
            if (i>15) strcat(health_bar.text, "2");
        }
}

void ChangeHealth(int modifier)
{
    g_PlayerHealth += modifier;
    if (g_PlayerHealth > 25) g_PlayerHealth = 25;
    if (g_PlayerHealth < 0) g_PlayerHealth = 0;
    UpdateHealthBar();
}

void SetHealth(int value)
{
    g_PlayerHealth = value;
    if (g_PlayerHealth > 25) g_PlayerHealth = 25;
    if (g_PlayerHealth < 0) g_PlayerHealth = 0;
    UpdateHealthBar();
}


We will now have a closer look on this three functions;
SetHealth function sets the player health to the value passed as it's parameter (int value). If the value is higher than maximum allowed (25 in my case), players health is set to the maximum. If it is lower that allowed minimum, it is set to the minimum (0 in my case). Then the UpdateHealthBar function is called.

ChangeHealth function works the same way the SetHealth function works, but instead of setting the g_PlayerHealth variable to have the value of the passed parameter (int modifier), it just adds the modifier to the current g_PlayerHealth value. Be the modifier -1, it substracts 1 point of health, be it 2, it adds 1 to the health value, but will never cross behind the minimum and maximum allowed values. Then UpdateHealthBar function is called.

UpdateHealthBar is the most important part, as it makes the health bar show the value of our g_PlayerHealth variable. You can see, there is a simple FOR cycle running g_PlayerHealth-times (so if we have g_PlayerHealth = 3, the loop will run 3 times). Just before the cycle, we erase everything in the text property of our "health_bar" actor. Than in each cycle, we write new character to the string so in the end, so be the g_PlayerHealth variable set to 3, we would have 3 characters in 'health_bar.text' string. As you can see, I use 3 different characters, so the bar will be red on one end, yellow in the middle and green on the other end, so it looks cool.

4)
We now have everything set up. In the game, we can just call ChangeHealth(modifier) or SetHealth(value) function and the health bar will react. Now, when the g_PlayerHealth variable has the value of 25, the bar looks like this:Image

Last words
Although my english is poor I hope you have understood the basics of creating a health bar. If not, just post here and I will try to explain it better.

I don't say that this is the best way how to do that, it's just the best I came up with.

it says to me
    illegal function definition in ex87926354810920
    undeclared indentifier UpdateHealthBar
[/list]

PostPosted: Thu Mar 01, 2007 12:34 am
by makslane
Put the code for the UpdateHealthBar function in the Global Code editor.

PostPosted: Thu Aug 16, 2007 5:13 pm
by diablos-bud
So does this health bar when you collide with another actor take away some health (and if it does how much health)?