Jump to content

(VBScript) Error with auto-update text box


Recommended Posts

Again with this game, I know.

 

I'm trying to make a text box that automatically updates based on the values of the other text boxes. Problem is, it comes up blank  :'(

 

Here's what I've got:

 

<html>
<head>
<title>Combat Game</title>
</head>
<body>

<script language="VBScript">
Sub TotalCosts
       TotalCost.Value = 200 - swordfootmen.Value - lancefootmen.Value - mountedswordsmen.Value - mountedlancemen.Value - bowmen.Value - horses.Value - catapaults.Value;
     End Sub
</script>

You may spend up to 150 gold. For unit prices and stength, consult <a href=unitstuff.php>this graph.</a>
<form>
Sword-wielding footmen:<input type="text" name="swordfootmen" onChange="TotalCosts"><br>
Lance-wielding footmen:<input type="text" name="lancefootmen" onChange="TotalCosts"><br>
Mounted sword wielders:<input type="text" name="mountedswordsmen" onChange="TotalCosts"><br>
Mounted lance wielders:<input type="text" name="mountedlancemen" onChange="TotalCosts"><br>
Bow-wielding footmen:<input type="text" name="bowmen" onChange="TotalCosts"><br>
Horses:<input type="text" name="horses" onChange="TotalCosts"><br>
Catapults:<input type="text" name="catapults" onChange="TotalCosts"><br>
<input type="submit" value="Attack!"><br>
<br>
<br>
Total money left: <input type="text" name="TotalCost" ReadOnly="True">

</form>
<?php
  $sfcost = $_REQUEST['swordfootmen'] * 3;
  $lfcost = $_REQUEST['lancefootmen'] * 3;
  $mswcost = $_REQUEST['mountedswordsmen'] * 5;
  $mlwcost = $_REQUEST['mountedlancemen'] * 5;
  $bcost = $_REQUEST['bowmen'] * 2;
  $hcost = $_REQUEST['horses'];
  $ccost = $_REQUEST['catapults'] * 12;
  $totalcost = $sfcost + $lfcost + $mswcost + $mlwcost + $hcost + $bcost + $ccost;
  $sfatk = $_REQUEST['swordfootmen'] * rand(1, 5);
  $lfatk = $_REQUEST['lancefootment'] * rand(2, 4);
  $mswatk = $_REQUEST['mountedswordsmen'] * rand(3, 5);
  $mlwatk = $_REQUEST['mountedlancemen'] * rand(3, 4);
  $hatk = $_REQUEST['horses'];
  $batk = $_REQUEST['bowmen'] * rand(1, 4);
  $catk = $_REQUEST['catapults'] * rand(6, 10);
  $totalatk = $sfatk + $lfatk + $mswatk + $mlwatk + $batk + $hatk + $catk;
  $compatk = rand(10, 200);
  if ( $totalcost > 200 )
    {
    echo "You spent too much money! <br />";
    }
  else
    {
    echo "Your total attack force is " . $totalatk . "<br />";
    
   echo 'The computers total attack force is ' . $compatk . "<br />";
  if ( $compatk > $totalatk )
    {
    echo 'Sorry, the computer wins...';
    }
  else
    {
    echo 'You win! Congratulations!';
    }
    }
?>
<br>
<br>
</body>
</html>

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.