Discussion forum for all Windows batch related topics.
Moderator: DosItHelp
-
AlphaBetaFullRelease
- Posts: 3
- Joined: 12 Mar 2017 13:44
#1
Post
by AlphaBetaFullRelease » 12 Mar 2017 14:01
Hello. I am working on a game that saves stats for particular accounts and loads them when an account is signed into. I have a problem, however: every time I sign in under the account 'testUser,' the game closes. The following is the code, and in red is where I
suspect the error is. (It might not be there.):
Code: Select all
@echo off
:startup
cls
title Batch RPG
color 0B
echo ----------Batch RPG----------
echo 1. New Account
echo 2. Singleplayer
echo 3. Multiplayer
echo 4. Exit
echo.
set /p answer= Enter the number next to the option you want:
if %answer% GEQ 5 (
cls
echo %answer% is invalid. Press any key to try again.
pause >nul
goto startup
)
if %answer% EQU 1 (
goto newAccount
)
if %answer% EQU 2 (
goto singleplayerLogin
)
if %answer% EQU 3 (
goto multiplayerLogin
)
if %answer% EQU 4 (
cls
echo Thank you for playing. Come again!
pause >nul
exit
)
:newAccount
cls
set /p player0Username= Enter your new username:
if exist %player0Username%.sav (
echo %player0Username% is already used. Press any key to go back.
pause >nul
goto startup
)
set /p player0CorrectPassword= Enter your new password:
cls
echo Now creating your account. Please so not close this program.
set player0LVL=1
set player0EXP=0
set player0NXT=5
set player0HP=8
set player0HPMax=8
set player0SP=2
set player0SPMax=2
set player0ATK=3
set player0DEF=1
set player0SPATK=4
set player0SPDEF=2
set player0Money=0
(
echo %player0Password%
echo %player0LVL%
echo %player0EXP%
echo %player0NXT%
echo %player0HP%
echo %player0HPMax%
echo %player0SP%
echo %player0SPMax%
echo %player0ATK%
echo %player0DEF%
echo %player0SPATK%
echo %player0SPDEF%
echo %player0Money%
) > %player0Username%.sav
cls
echo Thank you. Press any key to start playing.
pause >nul
goto singleplayerMenu
:singleplayerLogin
cls
set /p player0Username= Enter your username:
[color=#FF0000]if exist %player0Username%.sav (
< %player0Username%.sav (
set /p player0CorrectPassword=
set /p player0LVL=
set /p player0EXP=
set /p player0NXT=
set /p player0HP=
set /p player0HPMax=
set /p player0SP=
set /p player0SPMax=
set /p player0ATK=
set /p player0DEF=
set /p player0SPATK=
set /p player0SPDEF=
set /p player0Money=
)
set /p player0Password= Enter your password:
[/color] if %player0Password% EQU %player0CorrectPassword% (
cls
echo You're all signed in, %player0Username%. Press any key to start.
pause >nul
goto singleplayerMenu
) else (
cls
echo %player0Password% is incorrect. Press any key to try again.
pause >nul
goto singleplayerLogin
)
) else (
[color=#FF0000]echo %player0Username% is not valid. Press any key to try again.
pause >nul
goto singleplayerLogin
[/color])
:multiplayerLogin
:singleplayerMenu
pause
The following is the file created when I created the account 'testUser.' It is called 'testUser.sav':
testUser
1
0
5
8
8
2
2
3
1
4
2
0
I use Notepad++, which I think has no error handling. (I've looked through all the menus.) Any help regarding the error anywhere would be greatly appreciated.
-
Squashman
- Expert
- Posts: 4486
- Joined: 23 Dec 2011 13:59
#2
Post
by Squashman » 12 Mar 2017 19:52
There is no such thing as IF ELSE ELSE in batch files.
-
fugitive
- Posts: 19
- Joined: 09 Mar 2017 02:26
#3
Post
by fugitive » 13 Mar 2017 05:46
Squashman pointed out a syntax error of you,and i found another small mistake.
echo 1. New Account
echo 2. Singleplayer
echo 3. Multiplayer
echo 4. Exit
echo.
set /p answer= Enter the number next to the option you want:
if %answer% GEQ 5 (
if you input # @ $ ? ,you find # gtr 5 too!Maybe you could use this code :
Code: Select all
echo 1. New Account
echo 2. Singleplayer
echo 3. Multiplayer
echo 4. Exit
echo.
set /p answer= Enter the number next to the option you want:
echo;%answer%|findstr /b /e [1-4] >nul||(echo;%answer% is invalid. Press any key to try again.&pause>nul&goto startup )
-
Sounak@9434
- Posts: 100
- Joined: 16 Dec 2016 22:31
#4
Post
by Sounak@9434 » 13 Mar 2017 06:54
fugitive wrote:if you input # @ $ ? ,you find # gtr 5 too!Maybe you could use this code :
In my pc a string is detected as 0.
Code: Select all
@echo off
set answer=#
if # geq 5 echo WHAT
if # leq 5 echo NOOO
pause>nul
-
fugitive
- Posts: 19
- Joined: 09 Mar 2017 02:26
#5
Post
by fugitive » 13 Mar 2017 08:00
Sounak@9434 wrote:Code: Select all
@echo off
set answer=#
if # geq 5 echo WHAT
if # leq 5 echo NOOO
pause>nul
Oh my God, that's my fault. It should be # lss 0
-
AlphaBetaFullRelease
- Posts: 3
- Joined: 12 Mar 2017 13:44
#6
Post
by AlphaBetaFullRelease » 14 Mar 2017 15:40
Squashman wrote:There is no such thing as IF ELSE ELSE in batch files.
The second ELSE is part of the IF EXIST statement at the beginning of :singleplayerLogin
-
Squashman
- Expert
- Posts: 4486
- Joined: 23 Dec 2011 13:59
#7
Post
by Squashman » 14 Mar 2017 20:36
AlphaBetaFullRelease wrote:Squashman wrote:There is no such thing as IF ELSE ELSE in batch files.
The second ELSE is part of the IF EXIST statement at the beginning of :singleplayerLogin
Would help if you formatted your code for readability.
You are inside a parentheses code block. Any variables initialized within that code block that need to be referenced in that code block, need to be referenced with delayed expansion enabled and use exclamation points for the variable expansion instead of percent symbols.
-
AlphaBetaFullRelease
- Posts: 3
- Joined: 12 Mar 2017 13:44
#8
Post
by AlphaBetaFullRelease » 15 Mar 2017 17:25
Squashman wrote:AlphaBetaFullRelease wrote:Squashman wrote:There is no such thing as IF ELSE ELSE in batch files.
The second ELSE is part of the IF EXIST statement at the beginning of :singleplayerLogin
Would help if you formatted your code for readability.
You are inside a parentheses code block. Any variables initialized within that code block that need to be referenced in that code block, need to be referenced with delayed expansion enabled and use exclamation points for the variable expansion instead of percent symbols.
It pasted with tabs in place to indent. Does it ignore tabs?
-
ShadowThief
- Expert
- Posts: 1166
- Joined: 06 Sep 2013 21:28
- Location: Virginia, United States
#9
Post
by ShadowThief » 15 Mar 2017 17:27
AlphaBetaFullRelease wrote:Squashman wrote:AlphaBetaFullRelease wrote:The second ELSE is part of the IF EXIST statement at the beginning of :singleplayerLogin
Would help if you formatted your code for readability.
You are inside a parentheses code block. Any variables initialized within that code block that need to be referenced in that code block, need to be referenced with delayed expansion enabled and use exclamation points for the variable expansion instead of percent symbols.
It pasted with tabs in place to indent. Does it ignore tabs?
It does if you don't use code tags.