Confusion with Batch-file code -
so started learning batch-file, , today decided try , make game it. have few errors, , can't figure out wrong code. heres code:
@echo off title batch rpg color 07 echo welcome batch rpg! echo. echo. pause :menu cls echo. echo -menu- echo. echo. echo. echo 1) begin echo. echo 2) how play echo. echo 3) exit echo. echo. echo. echo --------- echo. set /p c=choice: if %c%==1 goto prestart1 if %c%==2 goto howtoplay if %c%==3 goto cfr_exit if not %c%==1 if not %c%==2 if not %c%==3 goto menu :cfr_exit cls echo. echo sure want exit? echo. set /p c=(y/n): if %c%=="y" exit if %c%=="n" goto menu if not %c%=="y" if not %c%=="n" goto cfr_exit2 :cfr_exit2 cls echo. echo must enter valid option. echo. pause goto cfr_exit :howtoplay cls echo. echo -how play- echo. echo. echo. echo game simple. there number option after it, type option in , perform action(as option say). echo. pause goto menu :prestart1 cls echo. echo welcome land of fageryth! echo. echo name, adventurer? echo. set /p playername=name: goto prestart2 :prestart2 cls echo. echo more valued statistic, attack damage, or hit points? echo. echo. echo. echo 1)attack damage(atk) echo. echo 2)hit points(hp) echo. echo. echo. echo --------- echo. set /p playermorevaluedstat=choice: if %playermorevaluedstat%==1 set playeratk=6 set playerhp=25 if %playermorevaluedstat%==2 set playeratk=4 set playerhp=30 if not %playermorevaluedstat%==1 if not %playermorevaluedstat%==2 goto prestart2 cls echo playeratk echo playerhp pause
i'm having trouble :prestart2
section of code. end of it, tried make if variable wasn't equal 1 or 2, options, send player start of section again, , also, when finishes checking, i'm trying make display 2 variables playeratk
, playerhp
instead closes out. lost here , appreciate help!
a couple things before start:
first, when troubleshooting batch scripts, rid of (comment out) echo off
, cls
lines can see it's going wrong.
second, should double-quote variables make sure you're not inadvertently including spaces when setting , comparing them. doesn't seem causing problems in code, it's habit into:
set "var1=something" set "var2=a string spaces" if "%var1%"=="something" echo %var1%
now, problem in code 2 if
statements stretching on multiple lines. if you're going that, have put them inside of parentheses.
set /p playermorevaluedstat=choice: if %playermorevaluedstat%==1 ( set playeratk=6 set playerhp=25 ) if %playermorevaluedstat%==2 ( set playeratk=4 set playerhp=30 )
Comments
Post a Comment