I need help with a game I'm making - Printable Version +- HomeTown Forums (https://hometownmc.com:443/forums) +-- Forum: General (https://hometownmc.com:443/forums/forumdisplay.php?fid=3) +--- Forum: Off Topic (https://hometownmc.com:443/forums/forumdisplay.php?fid=9) +--- Thread: I need help with a game I'm making (/showthread.php?tid=2238) |
I need help with a game I'm making - firegene - 03-29-2017 So I am making a text based game with Windows batch coding. Here is the code so far: @echo off title Game color 02 echo Once upon a time a girl walked into a cave. echo Upon entering she found a portal. Its surface was a deep purple, spirals all over its surface pause echo. :enter/run echo -------------------------------------------------------------------------------- echo [e] to enter the portal echo [r] to run away echo. set /p enter/run= cls if %enter/run%==e ( echo Your character takes a breath, closes her eyes, and steps forward. echo. echo Your characters body feels as if its being ripped apart. echo. echo Your character has lost consciousness. pause cls goto jail ) if %enter/run%==r ( echo Your character turns around and begins to run. echo. echo Your character feels a demon snatching at her feet. echo. echo Your character trips. echo. echo Your character has been dragged into the portal. pause cls goto jail ) if not %enter/run%==r ( echo ERROR echo INVALID ASNWER echo. echo PLEASE TRY AGAIN pause cls goto enter/run ) :jail cls echo Your character wakes up bleary-eyed in a cell. echo. echo Your character peers around, trying to see in the semi-darkness. pause cls :attack/go echo Your character hears a small voice saying, echo "Take this, use it to escape" echo. echo A small dagger drops into your character's lap. echo. echo Your character looks around for whoever has given you this weapon pause cls echo A guard flings the door open and shouts, echo "COME WITH ME" pause echo -------------------------------------------------------------------------------- echo [a] to attack the guard echo [g] to go with the guard echo. set /p attack/go= cls if %attack/go%==a ( cls color 0C set /a enemyHP = 25 echo YOUR CHARACTER HAS ENTERED BATTLE!!! echo. echo YOUR WEAPON IS A DAGGER. echo. echo YOUR CHARACTER HAS 100HP echo. echo YOUR ENEMY HAS %enemyHP%HP pause ) if %attack/go%==g ( ) if not %attack/go%==a ( echo ERROR echo INVALID ASNWER echo. echo PLEASE TRY AGAIN pause cls goto attack/go ) As you may have noticed I have highlighted some parts. These are the parts I need help with. It's meant to say that the enemy has (however large the variable is)HP Instead it says the enemy has HP So, can anyone tell me how this works. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ For anyone looking to run the game this what you do:
Please point out any bugs in the game. I will update this thread from time to time with updates on the game. RE: I need help with a game I'm making - Saiyaka - 03-29-2017 Why use batch though? You could do the same thing far more easily in a higher level language, like python. RE: I need help with a game I'm making - firegene - 03-29-2017 Batch is pretty easy to learn. Not many commands. Though I've never tried to learn any other language. RE: I need help with a game I'm making - Saiyaka - 03-29-2017 Batch may have somewhat simple commands, but it can sometimes be far off from plain English. That, and it's also very limited, which I'm about to show you. The reason why it doesn't work is because an if statement counts as a single command, and variables are expanded only when they're parsed. This is a common thing people run into once they start using for loops in batch, since this applies to any block of code. To get around this, you have to put "setlocal enabledelayedexpansion" at the top of your script and "! enemyHP!HP" instead of "%enemyHP%HP". The ! denotes a delayed expansion variable. I guess to put it in simpler terms, you can't set a variable and then read it in the same command, so either set the variable outside of the if statement, or enable delayed expansion and use !'s for any variables set inside the same code block rather than %'s. Or option 3: learn python lol RE: I need help with a game I'm making - CleeHawk - 03-29-2017 It's been a long time since I did this stuff but I agree with Saiyaka. Define the variable before the IF and it will work. Good luck with the game. I enclose the corrected code below. @echo off title Game color 02 echo Once upon a time a girl walked into a cave. echo Upon entering she found a portal. Its surface was a deep purple, spirals all over its surface pause echo. :enter/run echo -------------------------------------------------------------------------------- echo [e] to enter the portal echo [r] to run away echo. set /p enter/run= cls if %enter/run%==e ( echo Your character takes a breath, closes her eyes, and steps forward. echo. echo Your characters body feels as if its being ripped apart. echo. echo Your character has lost consciousness. pause cls goto jail ) if %enter/run%==r ( echo Your character turns around and begins to run. echo. echo Your character feels a demon snatching at her feet. echo. echo Your character trips. echo. echo Your character has been dragged into the portal. pause cls goto jail ) if not %enter/run%==r ( echo ERROR echo INVALID ASNWER echo. echo PLEASE TRY AGAIN pause cls goto enter/run ) :jail cls echo Your character wakes up bleary-eyed in a cell. echo. echo Your character peers around, trying to see in the semi-darkness. pause cls :attack/go echo Your character hears a small voice saying, echo "Take this, use it to escape" echo. echo A small dagger drops into your character's lap. echo. echo Your character looks around for whoever has given you this weapon pause cls echo A guard flings the door open and shouts, echo "COME WITH ME" pause echo -------------------------------------------------------------------------------- echo [a] to attack the guard echo [g] to go with the guard echo. set /p attack/go= cls set /a enemyHP = 25 if %attack/go%==a ( cls color 0C echo YOUR CHARACTER HAS ENTERED BATTLE!!! echo. echo YOUR WEAPON IS A DAGGER. echo. echo YOUR CHARACTER HAS 100HP echo. echo YOUR ENEMY HAS %enemyHP%HP pause ) if %attack/go%==g ( ) if not %attack/go%==a ( echo ERROR echo INVALID ASNWER echo. echo PLEASE TRY AGAIN pause cls goto attack/go ) RE: I need help with a game I'm making - firegene - 03-30-2017 Thanks clee!! RE: I need help with a game I'm making - Penguin - 04-10-2017 (03-29-2017, 04:33 AM)Saiyaka Wrote: Or option 3: learn python lol Python is great for beginners learning a third gen language, and it's object orientated! |