Probably a stupid question.

Non-platform specific questions.

Probably a stupid question.

Postby Raot » Wed Apr 27, 2011 11:38 pm

I'm trying to make a health bar. But my tiny monkey brain can't seam to make it shrink.

So, i have no previous knowledge of any kind of programing language except a week or so of Gamesalad(i made a game, but then realized i had pay 90 bucks for a profile or something if i wanted it tested. I decided to drop it for a more open source option.) and i read the first ten or so pages of "C++ for dummies" so far. I'm hoping to get more into it with time.

Anyway, i set it so that when "human"(my player) collides with "enemy1" then, script editor,

Code: Select all
healthbar.width=healthbar.width-50;


Like most program i write, it didn't work. The health bar stayed the same size. i wondered what the problem was, so i just just went to my healthbar and said that when i press tab,

Code: Select all
width=width-50;


didn't work either. It's probably some really simple thing I'm missing, but i couldn't find the answer on the forums. At least, not an answer i could comprehend.
Raot
 
Posts: 7
Joined: Thu Apr 21, 2011 8:14 pm
Score: 0 Give a positive score

Re: Probably a stupid question.

Postby skydereign » Thu Apr 28, 2011 12:13 am

Okay, first off width is what we call a read only variable. You can't edit it like you were trying to, it contains the width of the current frame. If you want to do a health bar, you need to either have an animation of an hp bar filling, or use some canvas method. Here are two examples, the animation one is easier coding wise, but you can do a lot of cool stuff with canvas (though it doesn't sound like you want that).

For using an animation, you might look here. Just look at the top example.
http://game-editor.com/HP_Bar

Here's a great example for using canavs.
http://game-editor.com/forum/viewtopic.php?f=6&t=5756
User avatar
skydereign
 
Posts: 3510
Joined: Mon Jul 28, 2008 8:29 am
Score: 589 Give a positive score

Re: Probably a stupid question.

Postby Raot » Thu Apr 28, 2011 4:09 pm

Alright, i got an animation(well, i'm working on the same animation problem i had before actually.) but now, i've declared "Health" as a global variable, and as an integer, went to "health bar" and said, draw actor,
Code: Select all
health=anipos;

and got an error "undeclared identifier health"
Raot
 
Posts: 7
Joined: Thu Apr 21, 2011 8:14 pm
Score: 0 Give a positive score

Re: Probably a stupid question.

Postby skydereign » Thu Apr 28, 2011 6:51 pm

You need a variable health for this to work, also it should be animpos = health. There are several ways to make global variables, I would go to global code and add this to it.
Code: Select all
int health;


Also, just to make sure, it is animpos. Of course depending on your health bar that code won't work. This should always work.
healthBar -> Draw Actor -> Script Editor
Code: Select all
animpos=(health/nframes)*maxHP;


maxHP needs to be replaced with the maxHP, and you still need the health variable declared. Anyways, you might look up variables, they will be extremely helpful to you.
User avatar
skydereign
 
Posts: 3510
Joined: Mon Jul 28, 2008 8:29 am
Score: 589 Give a positive score

Re: Probably a stupid question.

Postby Game A Gogo » Thu Apr 28, 2011 8:16 pm

Sky, I think you mean
Code: Select all
animpos=(health/maxHP)*nframes;

Your way was converting animpos into the health value ...

maxHP should still be your max health. probably 100 in this case.
Programming games is an art,
    Respect it.
User avatar
Game A Gogo
 
Posts: 3466
Joined: Wed Jun 29, 2005 10:49 pm
Location: French Canada *laughs*
Score: 181 Give a positive score

Re: Probably a stupid question.

Postby Raot » Thu Apr 28, 2011 9:21 pm

OK. So, my health bar has 11 frames. (full, 90%, 80%... 0%) so should i set the max HP to 11 or 10?

Also, I am pretty sure "Health" has been declared a variable now. However, i then set player->collision->enemy-> script editor,
Code: Select all
Health=Health-1;


All was fine, but it then gave me a message saying the "Health" had an error.
Raot
 
Posts: 7
Joined: Thu Apr 21, 2011 8:14 pm
Score: 0 Give a positive score

Re: Probably a stupid question.

Postby Game A Gogo » Thu Apr 28, 2011 9:58 pm

How did you declare your variable?

Also, the numbers of frames have nothing to do with maxHP. What is the maximum value you want Health to hold? that's what it is
Programming games is an art,
    Respect it.
User avatar
Game A Gogo
 
Posts: 3466
Joined: Wed Jun 29, 2005 10:49 pm
Location: French Canada *laughs*
Score: 181 Give a positive score

Re: Probably a stupid question.

Postby skydereign » Thu Apr 28, 2011 10:10 pm

Oh yeah... oops. Was leaving for class so I wasn't paying too much attention. One thing to note is it is easier if you have your hp animation fill, rather than deplete. If you are having it fill, then you'll have to change the equation to this.
Code: Select all
animpos=(maxHP-hp)/maxHP*nframes;
User avatar
skydereign
 
Posts: 3510
Joined: Mon Jul 28, 2008 8:29 am
Score: 589 Give a positive score

Re: Probably a stupid question.

Postby Raot » Fri Apr 29, 2011 12:11 am

I'm not quite sure how i declared it. i went to global code and there was a variable button, where i made a variable called "health".

However, whenever i then tried to use it later, it said "Undeclared identifier error"

So then i did what sky said and said,
int Health;
in the global editor and pressed add.

It proceeded to tell me that could not add it, because it already existed. This confused me, and prompted to to delete everything health related everywhere and try again.

Suddenly, after some exploration, i found, "Health" in "User vars" in the variable list. So i assumed something i did worked. thinking back now, it probably is not what i thought it was.
Raot
 
Posts: 7
Joined: Thu Apr 21, 2011 8:14 pm
Score: 0 Give a positive score

Re: Probably a stupid question.

Postby Game A Gogo » Fri Apr 29, 2011 9:04 am

variables are case sensitive. If you declared "health", use health, not Health. Also you cannot declare a variable twice, so either delete the variable found in the variables dialog or the one found the global script code.
Programming games is an art,
    Respect it.
User avatar
Game A Gogo
 
Posts: 3466
Joined: Wed Jun 29, 2005 10:49 pm
Location: French Canada *laughs*
Score: 181 Give a positive score


Return to General

Who is online

Users browsing this forum: No registered users and 1 guest