Save/Load Help
Posted: 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.):
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.
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.