Roy766 Posted May 24, 2008 Share Posted May 24, 2008 Well, I was making a combat game, and I have so far come up with the following code: <html> <head> <title>Combat Game</title> </head> <body> <form> Sword-wielding footmen:<input type="text" name="swordfootmen"><br> Lance-wielding footmen:<input type="text" name="lancefootmen"><br> Mounted sword wielders:<input type="text" name="mountedswordsmen"><br> Mounted lance wielders:<input type="text" name="mountedlancemen"><br> Horses:<input type="text" name="horses"><br> <input type="submit" value="Attack!"><br> </form> <?php $sfcost = $_REQUEST['swordfootmen'] * 3; $lfcost = $_REQUEST['lancefootmen'] * 3; $mswcost = $_REQUEST['mountedswordsmen'] * 5; $mlwcost = $_REQUEST['mountedlancemen'] * 5; $hcost = $_REQUEST['horses']; $totalcost = $sfcost + $lfcost + $mswcost + $mlwcost; $sfatk = $_REQUEST['swordfootmen'] * 2; $lfatk = $_REQUEST['lancefootment'] * 2; $mswatk = $_REQUEST['mountedswordsmen'] * 4; $mlwatk = $_REQUEST['mountedlancemen'] * 4; $totalatk = $sfatk + $lfatk + $mswatk + $mlwatk + $hcost; $compatk = rand(10, 150); if ( $totalatk > 150 ) { echo "You spent too much money!"; } else { echo "Your total attack force is " . $totalatk; } echo 'The computer's total attack force is ' . $compatk; if ( $compatk > $totalatk ) { echo 'Sorry, the computer wins...'; } else { echo 'You win! Congratulations!'; } ?> </body> </html> Well, I've been proofreading the file for the past 20 minutes, and I haven't found a thing. I have tried the above code on two different hosts: my freehostia and my T35. Freehostia pops up with: Parse error: parse error, unexpected T_STRING, expecting ',' or ';' in /home/www/roy766.freehostia.com/combatgame.php on line 35 and of course my T35 page just pops up with nothing, as usual. I have checked line 35 (the second if statement) so many times that I have it memorized, but I can't find a single thing wrong with it. If somebody finds some stupid mistake I made, I'm gonna slap myself to death . EDIT: Well, I defined the additional attack power of the horses with their cost...not like it matters. New line: $hatk = $_REQUEST['horses']; Line twenty-six is now: $totalatk = $sfatk + $lfatk + $mswatk + $mlwatk + $hatk; No difference in the error factor. EDIT: OH MY GOD! "computer's" ends the echo tag! I AM SO STUPID! Please delete topic! Link to comment https://forums.phpfreaks.com/topic/107027-solved-combat-game-not-working/ Share on other sites More sharing options...
Cory94bailly Posted May 24, 2008 Share Posted May 24, 2008 Try this for like 35: echo "The computers total attack force is $compatk"; Link to comment https://forums.phpfreaks.com/topic/107027-solved-combat-game-not-working/#findComment-548654 Share on other sites More sharing options...
Roy766 Posted May 24, 2008 Author Share Posted May 24, 2008 When I finished editing my post, you had replied with the error I found. One of the problems of having a large forum :-\ Link to comment https://forums.phpfreaks.com/topic/107027-solved-combat-game-not-working/#findComment-548655 Share on other sites More sharing options...
Cory94bailly Posted May 24, 2008 Share Posted May 24, 2008 When I finished editing my post, you had replied with the error I found. One of the problems of having a large forum :-\ Well it took me about 20 seconds to be honest.. Put it in my notepad2 and looked at line 35.. Please press the "Topic Solved" button! Link to comment https://forums.phpfreaks.com/topic/107027-solved-combat-game-not-working/#findComment-548657 Share on other sites More sharing options...
947740 Posted May 24, 2008 Share Posted May 24, 2008 Maybe you should check out my syntax highlighter-pretty useful for those kind of mistakes: http://www.phpfreaks.com/forums/index.php/topic,197539.msg891381.html#msg891381 Link to comment https://forums.phpfreaks.com/topic/107027-solved-combat-game-not-working/#findComment-548678 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.