Max hp

Game Editor comments and discussion.

Max hp

Postby beginnerirvaz » Sun Sep 25, 2011 8:18 pm

could somebody help me to set a max hp. I already have a hp in my game and items the player can collect to increase hp. I would like to set my hp so it can never go above 100 so if the hp was at 80 and an item collected was worth 30 the hp could only raise to 100.
Thanks everyone.
Irvaz
beginnerirvaz
 
Posts: 37
Joined: Fri Sep 09, 2011 2:02 am
Score: 0 Give a positive score

Re: Max hp

Postby skydereign » Sun Sep 25, 2011 8:25 pm

The following code will do just that. It increases the hp by 30, but has a max of 100, since min returns the smaller of the two.
Code: Select all
hp=min(hp+30,100);
User avatar
skydereign
 
Posts: 3510
Joined: Mon Jul 28, 2008 8:29 am
Score: 589 Give a positive score

Re: Max hp

Postby beginnerirvaz » Sun Sep 25, 2011 9:02 pm

Sorry for being stupid but could you explain that for me?
My hp is a bit complicated but basically I have used an array of 5
Health type 1 count(shows number on screen)
Health type 2 count(shows number on screen)
Total health count ( I want to show the average of 1 and 2)
Health type 1=100
Health type 2=100

So I need to set health type 1 and 2 so they can't ever be more than 100 each. If a enemy hits my player I say health type 1 or 2 -=watever the value

I have an array of health items that when you collect them they show on screen if u have 1 you can click and this adds hp to either health type 1, 2 or both but I never want this to go above 100 for each.

I hope I'm making sense, thanks.
Irvaz
beginnerirvaz
 
Posts: 37
Joined: Fri Sep 09, 2011 2:02 am
Score: 0 Give a positive score

Re: Max hp

Postby skydereign » Sun Sep 25, 2011 9:08 pm

Yeah, it makes sense, I did help you out with your hp system before. Essentially the code I gave is a way of limiting, while increasing any number. So whenever you increase a variable, you can use that to limit it.
Code: Select all
variable+=10; // this is the normal way to increase variable by 10

variable = min(variable+10, 100); // this way increases variable by 10, but limits it to a max of 100

Now if you need to use a variable in an array, just replace that. But anyways, whenever you increase the variable you don't want to have exceed 100, use that code and it will never exceed 100.
User avatar
skydereign
 
Posts: 3510
Joined: Mon Jul 28, 2008 8:29 am
Score: 589 Give a positive score

Re: Max hp

Postby beginnerirvaz » Sun Sep 25, 2011 10:07 pm

Hey sorry I didn't relies it was you, that's great exactly what I need. I'll not b able to try that for an hour but I'll let you know what happens. I'm still having some trouble making an average of some of my array.
Thanks
beginnerirvaz
 
Posts: 37
Joined: Fri Sep 09, 2011 2:02 am
Score: 0 Give a positive score

Re: Max hp

Postby skydereign » Mon Sep 26, 2011 1:22 am

Hmm... not sure what to tell you for the average thing. I can upload a ged for you, but all it would be is a text actor with that code I gave in its create actor. I'd need to know more about what is going wrong.
User avatar
skydereign
 
Posts: 3510
Joined: Mon Jul 28, 2008 8:29 am
Score: 589 Give a positive score

Re: Max hp

Postby master0500 » Mon Sep 26, 2011 2:45 am

Code: Select all
if (hp>100)
{
        hp=100;
}

would this work?
master0500
 
Posts: 409
Joined: Sun Jun 26, 2011 9:42 pm
Score: 27 Give a positive score

Re: Max hp

Postby skydereign » Mon Sep 26, 2011 2:50 am

It would, but using min is a better choice. It does the same thing, takes less lines, and doesn't involve an if.
User avatar
skydereign
 
Posts: 3510
Joined: Mon Jul 28, 2008 8:29 am
Score: 589 Give a positive score


Return to GE - General

Who is online

Users browsing this forum: No registered users and 1 guest