Working on a loop.
Moderator: InsideQC Admins
3 posts
• Page 1 of 1
Working on a loop.
I started working on a loop, and I am very new to loops. I was trying to figure this out alone, But I keep coming to a couple problems. FIrst of all, here is my code:
So basically, this is an energy bar. The minimum distance it should go is 222(x), and the maximum it can go is 422(x).
Then I want the health to be incorporated into the calculation, so it makes the graphics based on a health bar of 0-130. I don't want 0-30 to show, only 31-130. The health bar overlaps though, and It doesn't go all the way.
I got the number 4.22 by taking 422(maximum x value) and dividing it by 100. The health bar also scrolls from right to left, and it is supposed to go left to right. Any help on these would help. If not, Then it is all good.
- Code: Select all
h = cl.stats[STAT_HEALTH] * 2.22;
while (cl.stats[STAT_HEALTH] == cl.stats[STAT_HEALTH])
{
h++;
if (h > 422 || h < 222)
return;
life100 = Draw_CachePic ("gfx/energyb.lmp");
M_DrawPic ( (h-life100->width)/2, 20, life100 );
}
So basically, this is an energy bar. The minimum distance it should go is 222(x), and the maximum it can go is 422(x).
Then I want the health to be incorporated into the calculation, so it makes the graphics based on a health bar of 0-130. I don't want 0-30 to show, only 31-130. The health bar overlaps though, and It doesn't go all the way.
- Code: Select all
h = cl.stats[STAT_HEALTH] * 4.22;
I got the number 4.22 by taking 422(maximum x value) and dividing it by 100. The health bar also scrolls from right to left, and it is supposed to go left to right. Any help on these would help. If not, Then it is all good.
-

Mexicouger - Posts: 514
- Joined: Sat May 01, 2010 10:12 pm
The general format for a while loop is:
You must assure that at some point your condition change from true to false, otherwise your code won't never scape the loop and the program freezes:
As we can see, cl.stats[STAT_HEALTH] will always be equals to itself, so your loop won't never end.
- Code: Select all
while (condition is true) {do something}
You must assure that at some point your condition change from true to false, otherwise your code won't never scape the loop and the program freezes:
- Code: Select all
while (cl.stats[STAT_HEALTH] == cl.stats[STAT_HEALTH])
As we can see, cl.stats[STAT_HEALTH] will always be equals to itself, so your loop won't never end.
I know FrikaC made a cgi-bin version of the quakec interpreter once and wrote part of his website in QuakeC
(LordHavoc)
-

frag.machine - Posts: 2090
- Joined: Sat Nov 25, 2006 1:49 pm
Alright. I made it end earlier, But It wasn't giving me the right results.
EDIT:
And In my loop, I had
That made the while loop not be able to go any further down the bottom. But I suppose ++h could keep going
EDIT:
And In my loop, I had
- Code: Select all
if (h > 422) return;
That made the while loop not be able to go any further down the bottom. But I suppose ++h could keep going
-

Mexicouger - Posts: 514
- Joined: Sat May 01, 2010 10:12 pm
3 posts
• Page 1 of 1
Who is online
Users browsing this forum: No registered users and 1 guest