Saving progress/game

Discussion forum for all Windows batch related topics.

Moderator: DosItHelp

Post Reply
Message
Author
silent
Posts: 44
Joined: 28 Oct 2011 14:40

Saving progress/game

#1 Post by silent » 03 Jan 2012 10:30

Hi,i decided to make a Hacking simulator,like HackTheGame,and i want to do a saving thing.So if player will do 5 missions etc he will write save and it will save his progress to other file.

Code: Select all

::at start of program user gives his nickname
echo Write your nickname

set /p nickname=

if %nickname% ==goto start

::Now the saving command

set /p save=

if %save% == I DONT KNOW WHAT TO WRITE HERE

And it would save to a file with the username,so the user will be able to load his save only when he logged (in the program) with same nickname as is saved in the file.

silent
Posts: 44
Joined: 28 Oct 2011 14:40

Re: Saving progress/game

#2 Post by silent » 03 Jan 2012 10:45

and to load the save user needs to use command load

silent
Posts: 44
Joined: 28 Oct 2011 14:40

Re: Saving progress/game

#3 Post by silent » 04 Jan 2012 10:53

I got an idea,but i dont know if it will work,i thought about IF EXISTS but it would search for something that exists in a file,like IF EXISTS "GameSettings.txt" "Level=2" "Money=10" goto (and here the level thing,so if in file is Level=10 it goes to level 10)
Is it possible ? If yes pls gimme code :D

Squashman
Expert
Posts: 4465
Joined: 23 Dec 2011 13:59

Re: Saving progress/game

#4 Post by Squashman » 04 Jan 2012 11:26

Code: Select all

 FOR /F "tokens=1,2 delims==" %%I in (Gamesettings.txt) DO IF "%%I"=="Level" GOTO Level%%J

silent
Posts: 44
Joined: 28 Oct 2011 14:40

Re: Saving progress/game

#5 Post by silent » 04 Jan 2012 11:31

Hmm,when i write check (i will explain later,why check) it takes me back to level1 but in GameSettings.ini file (ive changed it from txt to ini) is

Code: Select all

level2

Full code of my testing batch file

Code: Select all

@echo off
:START
echo If you have been already playing,write 1 and you will be redirected to your level
echo If you want to play again write again

set /p saved=

if %saved% ==1 goto check
if %saved% ==again goto level1

:level1
echo Write 1
set /p task=

if %task% ==1 goto level2

:level2
echo level2 >GameSettings.ini
echo Write 2

set /p task=

if %task% ==1 goto level3

:level3
echo level3 >GameSettings.ini
echo Pause
pause

:WrongLevelSpecified
echo It seems something has benn done wrong
pause

:check
FOR /F "tokens=1,2 delims==" %%I in (Gamesettings.ini) DO IF "%%I"=="level" GOTO level%%J

:hehe
pause >nul


What happens ?

I have also used

Code: Select all

set /p var= <GameSettings.ini
if %var% ==level2 goto level2
if %var% ==level3 goto level3


But it was redirecting me to level 1 too :D

Oh,i forgot that i needed to write 1 to go to :check,but when i write 1,it goes to :hehe (its after the :check)

silent
Posts: 44
Joined: 28 Oct 2011 14:40

Re: Saving progress/game

#6 Post by silent » 04 Jan 2012 12:27

K,i have done the saving myself,with code

Code: Select all

set /p var= <GameSettings.ini
goto :%var%

but i want to save the users name with the level, how ?

Post Reply