ksun Posted January 15, 2013 Share Posted January 15, 2013 hi this is the skeleton code for a simple game thats suppose to take away 10 hp from enemy_hp each time the fight button is pressed but there seems to be something wrong with it, if anyone can help out, that would be gr8. the enemy hp seems to not fall below 90. <?php include('config.php'); include('user.php'); if(!loggedin()) { header("Location: login.php"); } $fight = $_POST['fight']; if($fight) { $defult = false; $enemy_hp = $enemy_hp - 10; echo $enemy_hp; } if(defult){ $user_hp = 100; $enemy_hp = 100; } $defult = true; ?> <body> <table width="444" height="278" border="3"> <tr> <td width="212"><form id="form1" name="form1" method="POST" action=""> <?php echo $user."\n <br>"; echo "hp = ".$user_hp; ?> <p><img src="images/monkey.png" width="108" height="97" /></p> <p> <input type="radio" name="attack" value="attack" /> attack</p> <p> <input type="radio" name="attack" value="radio" /> defend</p> <p> <input type="radio" name="attack" value="radio" /> skill 1 </p> <p> <input type="radio" name="attack" value="radio" /> <label for="radio"></label> skill 2</p> <p> <input type="radio" name="attack" value="radio" /> skill 3</p> <p> <input type="radio" name="attack" value="radio" /> skill 4</p> <p> <input type="submit" name="fight" value="fight" /> </p> </form></td> <td width="212"> <?php echo "ENEMY <br>"; echo "hp = ".$enemy_hp; ?> </tr> </table> </body> Quote Link to comment Share on other sites More sharing options...
BagoZonde Posted January 15, 2013 Share Posted January 15, 2013 It's because your script don't save $enemy_hp. PHP is server scripting language that means it's executed on server side so your code is terminated. You must save values to text file or better would be write it to database and then when script is executed, it must read $enemy_hp value. Maybe you would be interested with javascript and jQuery to do such things because variables are still available in memory of your computer. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.