Jump to content

Hello World 2!!


Kryllster

Recommended Posts

I am working on a turn based game and I am having some difficulty making the HP counter stop counting at the specified number here is some of the code;

 

<?php
session_start();
$player_hp = $_SESSION['player_hp'];
$turns = $_SESSION['turns'];
$turns = $turns - 1;
?>

 

and this is how I was trying to stop it.

<?php
if($total_hp < 30){
$player = $player_hp + 5;
echo "You Still Have More recovery to do!";
}
else {
echo "You are fully recovered!";
}
$_SESSION['turns'] = $turns;
$_SESSION['player_hp'] = $player_hp;
?>

I know this is simple but I'm having a heck of a time getting the HP to stop counting at 30.

Also here is the code which I use to refresh the page to count it out.

<form action="safe-spot.php" method="post">
<input type="hidden" name="sub">
<input type="submit" value="Click Here">

 

 

Thanks in advance,

Link to comment
Share on other sites

Can you go into a little more detail please? Is your problem that it is sometimes going above 30? If so, is it going above 34?

 

What are the $total_hp and $player variables supposed to represent? I would hazard a guess that this is the problem. This should work better, and will make the upper limit for HP hard:

 

<?php
session_start();
$_SESSION['turns']--;


if($_SESSION['player_hp'] < 30){

$_SESSION['player_hp'] += 5;



echo "You Still Have More recovery to do!";
}
else {


if($_SESSION['player_hp'] > 30) $_SESSION['player_hp'] = 30;
echo "You are fully recovered!";
}

?>

 

 

 

I've cut out the middle man here, as well. It now stores directly into the session.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.