|
Answer» I know this is a peculiar question, but here goes....
I'm MAKING a text game that will be constantly saving to "CurrentLevel.txt".
At the start menu, there is an option to load your last save. The code i used is...
SET /p GAMESTATECODE= IF "%GAMESTATECODE%"=="%GAMESTATECODE%" GOTO %GAMESTATECODE%
This works except, if someone tries to cheat, and changes their code to an invalid one, you get an error and it crashes.
The level codes will be the same as the labels.
Is there a way to create a label that will be whatever GAMESTATECODE is, and have it at the end, so if there is an invalid level code, it will display and error message?
NOTE: I did this to avoid having a huge amount of IF commands as there will be a huge amount of saves.
Code: [Select]SET /p game= <CurrentLevel.txt IF "%GAME%"=="" GOTO invalid if not exist file.dat goto invalid for /f "delims=" %%a in (file.dat) do if %g%=%%a goto %%a goto invalid create a read only file called file.dat with all accepted saves. for ex if accepted saves are 1 2 3 4 5 6 file.dat contains Code: [Select]1 2 3 4 5 6 create a label called invalid P.S could you pm me the game or post it here i would like to try it. Unless I've done something wrong, it still crashes... Thank you anyways though. I GUESS I'd RATHER have it crash than continue on..
----
I'm not finished yet, but i can post what is done if you'd like. It's just a simple text adventure kind of game, where you choose your path kind of thing.can i see the whole codeThis is what I have so far. I implanted you said and it still crashed, so I went back to what I had originally.
Thanks for your help.
Code: [Select]@ECHO OFF TITLE Game MODE CON: COLS=65 LINES=15 COLOR 02
:Menu
ECHO. ECHO ÉÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍ» ECHO º Main Menu º ECHO ÌÍÍÍÍÍÍÍÍÍÍÍÍÍÍ͹ ECHO º1. New Game º ECHO º º ECHO º2. Load Game º ECHO º º ECHO º3. Exit º ECHO ÈÍÍÍÍÍÍÍÍÍÍÍÍÍÍͼ ECHO. ECHO. ECHO What would you like to do? [1, 2, or 3] SET /p menu="" IF "%menu%"=="1" GOTO NewGame IF "%menu%"=="2" GOTO LoadGame IF "%menu%"=="3" EXIT
:NewGame
CLS IF EXIST CurrentLevel.txt DEL CurrentLevel.txt IF EXIST Name.txt DEL Name.txt ECHO Starting new game . . . ECHO. ECHO Note: When you quit, you will have to start your ECHO current level over next time you load. ECHO. PAUSE GOTO Start
:LoadGame
CLS IF NOT EXIST CurrentLevel.txt ECHO No saved game detected. IF NOT EXIST CurrentLevel.txt ECHO. IF NOT EXIST CurrentLevel.txt PAUSE IF NOT EXIST CurrentLevel.txt GOTO MENU SET /p name= <Name.txt SET /p GAMESTATECODE= <CurrentLevel.txt ECHO Loading Game . . . ECHO. ECHO NOTE: You will have to start your current mission over. ECHO. PAUSE IF "%GAMESTATECODE%"=="%GAMESTATECODE%" GOTO %GAMESTATECODE% CLS ECHO Unknown Level Code ECHO. PAUSE GOTO Menu
:Start
CLS ECHO "Welcome, you must be the new recruit." ECHO. ECHO "What is your name?" SET /p name="" ECHO %name%>Name.txt CLS
:Mission1Start
ECHO Mission1Start>CurrentLevel.txt
ECHO "Welcome %name%," ECHO. ECHO "Are you ready for your first mission?" Yes/No SET /p ready="" IF "%ready%"=="Yes" GOTO Level1 IF "%ready%"=="yes" GOTO Level1 IF "%ready%"=="No" GOTO RespNo IF "%ready%"=="no" GOTO RespNo CLS ECHO Unknown Command ECHO. PAUSE CLS GOTO Mission1Start
:RespNo
CLS ECHO "Sorry, %name% You don't have a choice." ECHO. PAUSE GOTO Level1
:Level1
ECHO Level1>CurrentLevel.txt
CLS ECHO "You're first mission is to infiltrate the enemy's nuclear ECHO facility. We need you to recover the plans they stole. ECHO You are going to need to be stealthy with this one, there ECHO are guards everywhere. DO NOT kill any of the scientists!" ECHO. ECHO "Are we clear?" SET /p clear="" IF "%clear%"=="No" GOTO Level1Unclear IF "%clear%"=="no" GOTO Level1Unclear IF "%clear%"=="Yes" GOTO Level1Clear IF "%clear%"=="yes" GOTO Level1Clear
:Level1Unclear
ECHO Level1Unclear>CurrentLevel.txt
CLS ECHO "That is unacceptable %name%, get out of my sight." ECHO. ECHO GAME OVER ECHO. PAUSE GOTO Menu
:Level1Clear
ECHO Level1Clear>CurrentLevel.txt
ECHO
CLS ECHO "Good." ECHO "Your plane leaves at 1600 HOURS." ECHO. PAUSE
CLS ECHO At 4 o'clock, you board the plane. waiting inside ECHO is all your equipment, and a parachute. ECHO While on the plane, you put all your equipment on ECHO and prepare yourself for the mission. ECHO. PAUSE
CLS ECHO "Alright recruit, JUMP!" ECHO. ECHO Jump? SET /p jump=""
CLS IF "%jump%"=="Yes" ECHO You jump out of the plane. IF "%jump%"=="yes" ECHO You jump out of the plane. IF "%jump%"=="No" ECHO %name%, Don't disobey me! IF "%jump%"=="No" ECHO. IF "%jump%"=="No" ECHO GAME OVER IF "%jump%"=="No" ECHO. IF "%jump%"=="No" PAUSE IF "%jump%"=="No" GOTO Menu IF "%jump%"=="no" ECHO "%name%, Don't disobey me!" IF "%jump%"=="no" ECHO. IF "%jump%"=="no" ECHO GAME OVER IF "%jump%"=="no" ECHO. IF "%jump%"=="no" PAUSE IF "%jump%"=="no" GOTO Menu
ECHO. PAUSE CLS ECHO When you land, you find yourself just outside ECHO of the nuclear facility. You are also on the ECHO outside of the fence. ECHO.
:Level1CoH
ECHO Level1CoH>CurrentLevel.txt
ECHO Would you like to try to climb the fence, ECHO or hide in the bushes? SET /p CoH="" IF "%CoH%"=="climb the fence" GOTO Level1Climb IF "%CoH%"=="hide in the bushes" GOTO Level1Bush ECHO. ECHO Unknown Command ECHO. PAUSE CLS GOTO Level1CoH
:Level1Climb
CLS ECHO As you climb the fence, a guard spots you. You ECHO attampt to jump down and take him out, but he ECHO is too quick. He shoots and kills you. ECHO. ECHO GAME OVER ECHO. PAUSE GOTO MENU
:Level1Bush
ECHO Level1Bush>CurrentLevel.txt
CLS ECHO You quickly run into the nearby bushes and hide. ECHO A few seconds later a guard walks by. He has a gun. ECHO. ECHO Would you like to attempt to take out the guard, ECHO or let him pass? SET /p KoP="" IF "%KoP%"=="knock out the guard" GOTO Level1KO IF "%KoP%"=="let him pass by" GOTO Level1LHP CLS ECHO Unknown Command ECHO. PAUSE GOTO Level1Bush
:Level1LHP
CLS ECHO The guard walks past you and you quickly start to climb ECHO the fence. The guard hears you and without delay turns ECHO and shoots you. ECHO. ECHO GAME OVER ECHO. PAUSE GOTO Menu
:Level1KO
ECHO Level1KO>CurrentLevel.txt
CLS ECHO As the guard passes by, you run up and break his neck. ECHO The dead guard falls to the ground. ECHO. ECHO You drag the knocked out guard into the bushes and climb ECHO over the fence. ECHO. PAUSE
:Level1DoC
ECHO Level1DoC>CurrentLevel.txt
CLS ECHO When you enter the building you notice the lights are off ECHO and the room is empty. There is a computer that is turned ECHO off beside you and a closed door on the far side. ECHO. ECHO Would you like to use the computer or open the door? SET /p DoC="" IF "%DoC%"=="use the computer" GOTO Level1Computer IF "%DoC%"=="open the door" GOTO Level1Door CLS ECHO Unknown Command ECHO. PAUSE GOTO Level1DoC
:Level1Door
CLS ECHO You head over to the door and puch it open. Inside you find ECHO three guards sitting AROUND a table. They notice you, and ECHO quickly raise their guns and fire. ECHO. ECHO GAME OVER ECHO. PAUSE GOTO Menu
:Level1Computer
ECHO Level1Computer>CurrentLevel.txt
CLS ECHO You head over the the computer and find that it requires a ECHO password. You also hear movement in the other room. ECHO. ECHO Would you like to find a hiding spot or try to guess the ECHO password? SET /p PoH="" IF "%PoH%"=="try to guess the password" GOTO Level1Password IF "%PoH%"=="find a hiding spot" GOTO Level1Hide CLS ECHO Unknown Command ECHO. PAUSE GOTO Level1Computer
:Level1Password
CLS ECHO You sit down at the computer and start guessing passwords. ECHO As you are sitting at the computer, a guard enters the room ECHO from the far door. He sees you and open fire. ECHO. ECHO GAME OVER ECHO. PAUSE GOTO Level1Computer
:Level1Hide
CLS ECHO You quickly run over to a corner of the room and hide behind ECHO a desk. The room is dark, so you hope nobody will see you. A ECHO guard walks in and sits at the computer. Now's your chance. ECHO. ECHO Would you like to take down the guard or wait him out? SET /p ToW="" IF "%ToW%"=="wait him out" GOTO Level1Wait IF "%ToW%"=="take down the guard" GOTO Level1TakeDown CLS ECHO Unknown Command ECHO. PAUSE GOTO Level1Hide
:Level1Wait
CLS ECHO you sit for a while waiting for the guard to leave. You hear ECHO somebody else enter the room. He comes over to the desk you ECHO are hiding behind and sees you. He draws his rifle and shoots ECHO you. ECHO. ECHO GAME OVER ECHO. PAUSE GOTO Level1Hide
:Level1TakeDown
CLS ECHO You sneak up behind to guard sitting at the computer. You grab ECHO him by the neck and break it. He falls to the floor. ECHO. PAUSE CLS ECHO After hiding the body in the closet nearby, you go back to the ECHO computer. You find that the guard had entered the password and ECHO you now have access to the computer. ECHO.
:Level1WoR
ECHO On the computer you find the blueprints of the nuclear facility. ECHO You learn that you can access every room via the air vents. ECHO. ECHO Would you like to go to the weapons room or the research room? SET /p WoR="" IF "%WoR%"=="go to the weapons room" GOTO Level1Weapons IF "%WoR%"=="go to the research room" GOTO Level1Research CLS ECHO Unknown Command ECHO. PAUSE GOTO Level1WoR
:Level1Weapons
CLS ECHO You make your way through the air ducts to the weapons room. ECHO You look through the vent and see that nobody is in the room. ECHO You climb out of the vent and search through the desks, but ECHO as you check in the last desk drawer, a guard walks in. He ECHO is unarmed. ECHO. PAUSE CLS ECHO The guard lunges towards you and manages to wrestle you to ECHO the ground. He grabs the knife that was attached to his belt ECHO and brings it down on your chest. ECHO. ECHO GAME OVER ECHO. PAUSE GOTO Menu
:Level1Researchsorry i did not test the code i gave you so it had errors replace the for line with this
for /f %%a in (file.dat) do if %game%==%%a goto %%aAhh, works perfectly thank you soo much!
|