Page 1 of 1

Before And After Looping

Posted: Mon Sep 30, 2013 10:27 am
by Epiales
Okay, as ya know, I have my arena system kinda sorta done :D

What I want is to be able to count the amount of guards and hitpoints both users lose during the battle loops. I thought of earlier, getting the before the loop amounts BEFORE the loops / battle actually starts, and then the AFTER amounts. The problem I'm running into, with my thinking, is that if I create a variable that defines the hitpoints before the battle, then, of course, that variable will change with each loops in the battle, so it would be the same at the end. I think I may be answering myself as I type. Maybe the database is the key, but still wouldn't know how to keep the current hitpoints from changing as the battle went on.

Example:

$beforehitpoints = $currenthitpoints...

But the $currenthitpoints would change when you looped through the battle, so how would I store the original amount of hitpoints that they began with and then at the end, do some simple math to figure out how many hitpoints they lost and echo that to the user? If I just echo the hitpoints BEFORE the loop and then AFTER the loop, it does what I expected it to do; exact same amounts :cry: :cry:

Re: Before And After Looping

Posted: Mon Sep 30, 2013 10:58 am
by Winawer
Why not just

Code: Select all

$beforehitpoints = $currenthitpoints;
while( isFighting() ) {
    $currenthitpoins -= calcDamage();
}
echo 'original HP: ', $beforehitpoints,  '<br />';
echo 'current HP: ', $currenthitpoints, '<br />';
echo 'HP lost: ', ( $beforehitpoints - $currenthitpoints );

Re: Before And After Looping

Posted: Mon Sep 30, 2013 11:02 am
by Epiales
Winawer wrote:Why not just

Code: Select all

$beforehitpoints = $currenthitpoints;
while( isFighting() ) {
    $currenthitpoins -= calcDamage();
}
echo 'original HP: ', $beforehitpoints,  '<br />';
echo 'current HP: ', $currenthitpoints, '<br />';
echo 'HP lost: ', ( $beforehitpoints - $currenthitpoints );
 
I tried something like that but the beforehitpoints, since they equal the currenthitpoints, then when you echo the before - the current, they equal one another out and it is always zero, as the before hitpoints is the same as the currenthitpoints. If that makes sense.

Re: Before And After Looping

Posted: Mon Sep 30, 2013 11:06 am
by Epiales
Now I tried something like this:

Code: Select all

<?php
$a_arenahitpoints = $stats['arena'];
$updatebeforehpoints="update stats set arena='$stats[hpoints]' WHERE id='$_SESSION[uid]'";
mysql_query($updatebeforehpoints) or die ("Could not update player");
?>

I created that before the loops, and also added a table in the database for the stats arena....

Then I placed this after the fight:

Code: Select all

$losthp = $stats['hpoints'] - $a_arenahitpoints;
It seems to be doing something, as the numbers don't stay the same, but I'm having a hard time figuring out if it's actually working properly because my stats don't update as I need them. They are always one battle, or one hit behind. Plus, as the cronjob runs every minute, it gives more hitpoints, which makes the number sometimes positive and sometimes negative, so it's a big mess if you ask me LOL :evil: :evil: :evil:

Re: Before And After Looping

Posted: Mon Sep 30, 2013 11:23 am
by Epiales
Winawer wrote:Why not just

Code: Select all

$beforehitpoints = $currenthitpoints;
while( isFighting() ) {
    $currenthitpoins -= calcDamage();
}
echo 'original HP: ', $beforehitpoints,  '<br />';
echo 'current HP: ', $currenthitpoints, '<br />';
echo 'HP lost: ', ( $beforehitpoints - $currenthitpoints );
 
This is what I get with doing exactly what you have put:

You have defeated carl, and have won 8 points!
original HP: 135
current HP: 135
HP lost: 0

See how they zero one another out?

Re: Before And After Looping

Posted: Mon Sep 30, 2013 11:27 am
by Xaos
A few options here.

Make just one variable, $hitpoints. Echo this at the beginning. Then run through the loop and etc. wontbe able to use it afterwards however
Make an array and after each 'round' of the fight, add the HP to the array. Ie $hitpoints[0] would be the starting hp.
Echo starting hp, then check if huge loop conditions are met, then change the beginning to current inside of the loop.
Have the two different variable. Use beginning and return it to $x , set $current to $beggining, after each round update $y as current.

Re: Before And After Looping

Posted: Mon Sep 30, 2013 11:30 am
by Epiales
Xaos wrote:A few options here.

Make just one variable, $hitpoints. Echo this at the beginning. Then run through the loop and etc. wontbe able to use it afterwards however
Make an array and after each 'round' of the fight, add the HP to the array. Ie $hitpoints[0] would be the starting hp.
Echo starting hp, then check if huge loop conditions are met, then change the beginning to current inside of the loop.
Have the two different variable. Use beginning and return it to $x , set $current to $beggining, after each round update $y as current.
Is that English?

:D :lol: :lol: :D :lol: :lol: :D

You lost me on array LOL! I don't know much about em lol. I'll do some googlin' :mrgreen: :mrgreen:

Re: Before And After Looping

Posted: Mon Sep 30, 2013 11:39 am
by Xaos
Epiales wrote:
Xaos wrote:A few options here.

Make just one variable, $hitpoints. Echo this at the beginning. Then run through the loop and etc. wontbe able to use it afterwards however
Make an array and after each 'round' of the fight, add the HP to the array. Ie $hitpoints[0] would be the starting hp.
Echo starting hp, then check if huge loop conditions are met, then change the beginning to current inside of the loop.
Have the two different variable. Use beginning and return it to $x , set $current to $beggining, after each round update $y as current.
Is that English?

:D :lol: :lol: :D :lol: :lol: :D

You lost me on array LOL! I don't know much about em lol. I'll do some googlin' :mrgreen: :mrgreen:

I think a huge thing you could do is reassign them to other variables and that way you have a lot of manipulation. Especially if your ot good with arrays

Re: Before And After Looping

Posted: Mon Sep 30, 2013 12:05 pm
by Callan S.
Are you refreshing your page (the page is reloaded) for this loop? Or it's all done on one page?

I'm not sure why recording the hitpoints into some storage value before you start the loop doesn't solve your problem?
Example:

$beforehitpoints = $currenthitpoints...

But the $currenthitpoints would change when you looped through the battle, so how would I store the original amount of hitpoints that they began with
You store it in $beforehitpoints before you start the loop (not during the loop)

Re: Before And After Looping

Posted: Mon Sep 30, 2013 12:19 pm
by Epiales
Callan S. wrote:Are you refreshing your page (the page is reloaded) for this loop? Or it's all done on one page?

I'm not sure why recording the hitpoints into some storage value before you start the loop doesn't solve your problem?
Example:

$beforehitpoints = $currenthitpoints...

But the $currenthitpoints would change when you looped through the battle, so how would I store the original amount of hitpoints that they began with
You store it in $beforehitpoints before you start the loop (not during the loop)
No, the page is not refreshed. You click on their name, which takes you to an attack page, and on that page, the battle occurs and the loop occurs. Then at the end it lets you know the results. Well, I'm working on that. But no, it's not refreshed.

And you see the result above where I did the variable beforehitpoints before the loop and then echoed the hitpoints after the loop. They are always the same number, as both variables equal the current hitpoints. Whether before the loop or after, they are the same.