49 users online (0 members and 49 guests)  


  Results 1 to 2 of 2

Related

  1. Turnkey Online Businesses is the Best way to Earn Money Online in 2014    Forum: Affiliate Marketing and Reseller Programs
    Replies: 0
  2. die function    Forum: CGI Perl Forum
    Replies: 2
  1. #1
    tenniskid493's Avatar
    New User

    Status
    Offline
    Join Date
    Jan 2006
    Posts
    2

    Online Battle Engine...Function not working

    Help, I'm making an online battle game and am currently making the text version just to get the equations working. I keep getting this error:
    I can't seem to find what the error is. Can anyone help me. Here's my code:
    Code:
    <html>
    <head>
    <script type="text/javascript">
    var name=document.player.name.value;
    var element=document.player.element.value;
    var level=document.player.level.value;
    var health=document.player.health.value;
    var magic=document.player.magic.value;
    var speed=document.player.speed.value;
    var attack=document.player.attack.value;
    var defense=document.player.defense.value;
    var name1=document.enemy.name.value;
    var element1=document.enemy.element.value;
    var level1=document.enemy.level.value;
    var health1=document.enemy.health.value;
    var magic1=document.enemy.magic.value;
    var speed1=document.enemy.speed.value;
    var attack1=document.enemy.attack.value;
    var defense1=document.enemy.defense.value;
    function attack()
    {
    document.enemy.health.value=parseInt(health1)-10;
    }
    </script>
    </head>
    <body>
    <table><tr><td><form name="player">
    Name <input type="text" size="20" name="name" value="Brian"><br>
    Element <input type="text" size="20" name="element" value="Fire"><br>
    Level <input type="text" size="20" name="level" value="25"><br><br>
    Health <input type="text" size="20" name="health" value="500"><br>
    Magic <input type="text" size="20" name="magic" value="250"><br>
    Speed <input type="text" size="20" name="speed" value="100"><br>
    Attack <input type="text" size="20" name="attack" value="125"><br>
    Defense <input type="text" size="20" name="defense" value="115"><br>
    </form></td><td><form name="enemy">
    Name <input type="text" size="20" name="name" value="Enemy"><br>
    Element <input type="text" size="20" name="element" value="Water"><br>
    Level <input type="text" size="20" name="level" value="23"><br><br>
    Health <input type="text" size="20" name="health" value="465"><br>
    Magic <input type="text" size="20" name="magic" value="285"><br>
    Speed <input type="text" size="20" name="speed" value="85"><br>
    Attack <input type="text" size="20" name="attack" value="105"><br>
    Defense <input type="text" size="20" name="defense" value="100"><br>
    </td></tr></table>
    <input type="button" value="Attack" onclick="attack()">
    <input type="button" value="Defend" onclick="defend()">
    <input type="button" value="Fireball" onclick="fireball()">
    <input type="button" value="Lightning" onclick="lightning()">
    <input type="button" value="Heal" onclick="heal()">
    </body></html>
    Attached Images Attached Images
    Last edited by HTML; 01-28-2006 at 08:09 PM. Reason: attached image

  2. #2
    coothead's Avatar
    bald headed old fart

    Status
    Offline
    Join Date
    Aug 2003
    Location
    chertsey, a small town 25 miles south west of london, england.
    Posts
    732

    Re: Online Battle Engine...Function not working

    Hi there tenniskid493,

    you are having conflicts with function names and var names.
    try it like this...
    Code:
    <html>
    <head>
    <script type="text/javascript">
    <!--
    function attack() {
    var nme=document.player.nme.value;
    var element=document.player.element.value;
    var level=document.player.level.value;
    var health=document.player.health.value;
    var magic=document.player.magic.value;
    var speed=document.player.speed.value;
    var attck=document.player.attck.value;
    var defense=document.player.defense.value;
    var name1=document.enemy.nme.value;
    var element1=document.enemy.element.value;
    var level1=document.enemy.level.value;
    var health1=document.enemy.health.value;
    var magic1=document.enemy.magic.value;
    var speed1=document.enemy.speed.value;
    var attack1=document.enemy.attck.value;
    var defense1=document.enemy.defense.value;
    document.enemy.health.value=parseInt(health1)-10;
    //-->
    }
    </script>
    
    </head>
    <body>
    <table><tr>
    <td>
    <form name="player">
    Name <input type="text" size="20" name="nme" value="Brian"><br>
    Element <input type="text" size="20" name="element" value="Fire"><br>
    Level <input type="text" size="20" name="level" value="25"><br><br>
    Health <input type="text" size="20" name="health" value="500"><br>
    Magic <input type="text" size="20" name="magic" value="250"><br>
    Speed <input type="text" size="20" name="speed" value="100"><br>
    Attack <input type="text" size="20" name="attck" value="125"><br>
    Defense <input type="text" size="20" name="defense" value="115"><br>
    </form>
    </td>
    <td>
    <form name="enemy">
    Name <input type="text" size="20" name="nme" value="Enemy"><br>
    Element <input type="text" size="20" name="element" value="Water"><br>
    Level <input type="text" size="20" name="level" value="23"><br><br>
    Health <input type="text" size="20" name="health" value="465"><br>
    Magic <input type="text" size="20" name="magic" value="285"><br>
    Speed <input type="text" size="20" name="speed" value="85"><br>
    Attack <input type="text" size="20" name="attck" value="105"><br>
    Defense <input type="text" size="20" name="defense" value="100"><br>
    </td>
    </tr></table>
    <input type="button" value="Attack" onclick="attack()">
    <input type="button" value="Defend" onclick="defend()">
    <input type="button" value="Fireball" onclick="fireball()">
    <input type="button" value="Lightning" onclick="lightning()">
    <input type="button" value="Heal" onclick="heal()">
    </body></html>