Very simple question.
I am creating a simple texted based game in batch. It is about you are a pilot for the airline and you need to stop it from crashing into a random variable. Before you "take off" you need to edit your programming terminal and tell it your fuel. The fuel is marked with %fuel%. So when you are in the air. Your Turn will cost you 1000L of Fuel so if I input 54000 i will have 54 turns to get the plane safely landed. The code for the fuel input and display are here I just need the code to have the %fuel% - 1000
:fuel
cls
color c
echo ----------------------------------------
echo FUEL NEEDED FOR FLIGHT
echo ----------------------------------------
echo Awnser in Litres Please
echo eg 54000
echo -----------------------------------------
set /p fuel=""
echo -----------------------------------------
echo Is this Correct Y/N
echo -----------------------------------------
set /p c4=""
if /I "%c4%" EQU "Y" goto :d4
if /I "%c4%" EQU "N" goto :fuel
goto :fuel
:d4
color a
cls
echo ---------------------------------------
echo Flight Navigation System
echo %dep% to %arr%
echo Heading %heading% Degrees
echo ----------------------------------------
echo Captain - %captain%
echo 1st Officer - %officera%
echo 2nd Officer - %officerb%
echo Head Flight Attenedent - %hfa%
echo ----------------------------------------
echo FUEL - %fuel% Litres Remaining
echo ----------------------------------------
pause
Use "Set /a fuel-=1000". If you are using XP you might need to do "Set /a fuel= %fuel%-1000"
Related
I am trying to make a quick program in Batch that asks for user input, but when i get to the input part, the script exits with error:
The syntax of the command is incorrect.
This is my code:
#echo off
color 0a
title WinDoS/PoD- 0.1
echo Automatic DoS/PoD Tool
echo Select what you want to do.
echo 1. Attack
echo 2. Instructions
echo 3. IP Getter
echo 4. IP Searcher
echo 5. Exit
set /p userchoice=
if %userchoice% == 1
goto attack
if %userchoice% == 2
goto instructions
if %userchoice% == 3
goto getter
if %userchoice% == 4
goto searcher
if %userchoice% == 5
exit
:searcher
arp -a
pause
:attack
echo Enter IP adress to attack
set /p address=
goto sequence
:sequence
ping %address% -l 65500 -w 1 -n 1
goto sequence
:instructions
echo WinDoS/PoD Instructions
echo WinDoS/PoD is a program that allows you to perform Denial Of Service (DoS) attacks using a method known as Ping Of Death (PoD)
echo Press 1 on the home menu to enter the attacker program.
echo Input an ip address to DoS
echo If you don't know the IP address to a site, use the built in getter.
echo If you want to view all available network targets, use the built in searcher.
pause
:getter
echo Website (full link):
set /p %website%=
tracert %website%
pause
What is wrong with the syntax?
You're using the wrong command for choosing a known list item, you should be using choice, not set.
Here's an example using your provided information as its basis:
#Echo Off
Color 0A
Title WinDoS/PoD- 0.1
:Menu
Echo(
Echo Automatic DoS/PoD Tool
Echo(
Echo Home Menu
Echo(
Echo 1. Attack
Echo 2. Instructions
Echo 3. IP Getter
Echo 4. IP Searcher
Echo 5. Exit
Echo(
%__AppDir__%choice.exe /C 12345 /N /M "Select a Home Menu item number>"
If ErrorLevel 5 GoTo :EOF
If ErrorLevel 4 GoTo Searcher
If ErrorLevel 3 GoTo Getter
If ErrorLevel 2 GoTo Instructions
:Attack
ClS
Set /P "address=Enter IP address to attack> "
:Sequence
%__AppDir__%ping.exe %address% -l 65500 -w 1 -n 1
GoTo Sequence
:Instructions
ClS
Echo WinDoS/PoD Instructions
Echo(
Echo This program allows you to perform Denial Of Service (DoS) attacks,
Echo using a method known as Ping Of Death (PoD).
Echo(
Echo Press 1 on the Home Menu to begin the Attack program.
Echo Input an IP address to DoS
Echo If you don't know the IP address for a site, use the built-in Getter.
Echo If you want to view all available network targets, use the built-in Searcher.
Echo(
Pause
GoTo Menu
:Getter
ClS
Set /P "website=Website (full link)> "
%__AppDir__%tracert.exe %website%
Pause
GoTo Menu
:Searcher
ClS
%__AppDir__%arp.exe -a
Pause
GoTo Menu
Please note, that I have not looked at the usage of any of your commands, I have offered only improvements to the layout and functionality.
So i was writing a Batch file, and i made a file that you can choose an answer by a question, and its saves it automaticly to a file. But i want to make something before it saves it to a file, to let people confirm their choices. Simplified, i have it like this:
Rem Question 1 appearance
:q1
cls
Echo.
Echo Please select your age:
Echo ==================
Echo A) younger than 18
Echo B) 18-30
Echo C) 30-45
Echo D) older than 45
Echo.
Echo.
Rem Question 1 in- and output settings
:q1.2
set INPUT=
set /p INPUT=Answer:
if "%INPUT%"=="A" Echo You chose an age of less than 18. & pause & goto q2
if "%INPUT%"=="B" Echo You chose an age of 18-30. & pause & goto q2
if "%INPUT%"=="C" Echo You chose an age of 30-45. & pause & goto q2
if "%INPUT%"=="D" Echo You chose an age of older than 45. & pause & goto q2
Echo Please enter a valid answer!
goto q1.2
Rem question 2 appearance
:q2
Echo Answer: %INPUT% >>Question1answers.txt
cls
Echo.
Echo Please select your favourite colour:
Echo ==========================
Echo A) Blue
Echo B) Red
Echo C) Green
Echo D) Yellow
Echo E) Other
Echo.
Echo.
Rem Question 2 in- and output settings
:q2.1
set INPUT=
set /p INPUT=Answer:
if "%INPUT%"=="A" Echo You chose blue.&pause&goto end
if "%INPUT%"=="B" Echo You chose red.&pause&goto end
if "%INPUT%"=="C" Echo You chose green.&pause&goto end
if "%INPUT%"=="D" Echo You chose yellow.&pause&goto end
if "%INPUT%"=="E" Echo You chose something else.&pause&goto end
Echo Please enter a valid answer!
goto q2.1
So i ask you to not reply with the full code, maybe a little piece so i can learn from it and put it in myself, you know? Thanks!
Edit:
So now i added this part:
:confirmation
cls
Echo Please make sure this is your data:
if "%INPUTT%"=="A" Echo You chose an age of less than 18.
if "%INPUTT%"=="B" Echo You chose an age of 18-30.
if "%INPUTT%"=="C" Echo You chose an age of 30-45.
if "%INPUTT%"=="D" Echo You chose an age of older than 45.
echo.
if "%INPUT%"=="A" Echo You chose blue as your favourite colour.
if "%INPUT%"=="B" Echo You chose red as your favourite colour.
if "%INPUT%"=="C" Echo You chose green as your favourite colour.
if "%INPUT%"=="D" Echo You chose yellow as your favourite colour.
if "%INPUT%"=="E" Echo You chose something else as your favourite colour.
choice /m "Is this your data?" /d Y
if %errorlevel%==1 goto q1
Echo Answer: %INPUTT% >>Question1answers.txt
Echo Answer: %INPUT% >>Question2answers.txt
So i started debugging and when i came to the part it was wrong, it let me through and still saved my input. it kind of ignores the part of
if %errorlevel%==1 goto q1
so what do i do now?
since you ask for a short snippet, this should do what you want:
set /p "age=Enter your age: "
choice /M "Your age is %age%, correct?"
if %errorlevel%==1 goto :correct
echo false
goto :eof
:correct
echo true
I am new to batch coding and I am having an issue where whenever I select an option, it goes to 1 (which is :MEMBERS) even if I enter 2 or 3. I am unsure why this is happening.
#echo off
cls
color A
:MENU
cls
echo ===============================
echo Mavast Client v0.01
echo ===============================
echo Enter a number from the list and hit enter
echo to run that program.
echo 1. Members
echo 2. Support us
echo 3. Exit
set /p var= Run:
if %var%=="1" goto MEMBERS
if %var%=="2" goto SUPPORT
if %var%=="3" goto EXIT
:MEMBERS
cls
echo Owner/Rifler = C0MpL3T3
echo Admin/Stratcaller = TDGR (The Dutch Grim Reaper)
echo Awper = NONE
echo Lurker = NONE
echo Entry Fragger = NONE
echo press any key to continue
timeout -1 > NUL
goto MENU
:SUPPORT
cls
echo Support us by donating BitCoins or skins
echo to donate skins, just trade them to TDGR or C0MpL3T3.
echo to donate bitcoins, send any amount you want to this address:
echo 1DSRHe7L842MZjwTWYPzgGzbsZ8zU97w9g
echo thank you!
echo press any key to continue
timeout -1 > NUL
goto MENU
:EXIT
cls
exit
try with
if "%var%"=="1" goto MEMBERS
if "%var%"=="2" goto SUPPORT
if "%var%"=="3" goto EXIT
Quotes are also compared in IF conditions.
So I'm making a game based on making decisions using notepad ++ and batch. I'm new to this and I have no idea what the problem is here.
:start
;startup
cls
echo Wine or Cheese?
echo.
echo 1. Wine
echo 2. Cheese
echo 3. Exit
echo.
set /p input0=Enter:
if %input0% equ 1 goto winestart
if %input0% equ 2 goto cheese
if %input0% equ 3 goto exit
When I select winestart or 1, it goes to winestart for a splitsecond then crashes, with the error message: 1 was unexpected at this time.
Winestart looks like this:
:winestart
cls
echo You are alone. You have a bottle of wine and the clothes you are wearing.
echo What kind of wine do you have?
echo.
echo 1. Red Wine
echo 2. White Wine
set p/ input7=Enter:
if %input7% equ 1 goto redwine
if %input7% equ 2 goto whitewine
/p indicates that the variable is simply set by user input. –
SET
:winestart
cls
echo You are alone. You have a bottle of wine and the clothes you are wearing.
echo What kind of wine do you have?
echo.
echo 1. Red Wine
echo 2. White Wine
set /p input7=Enter:
if %input7% equ 1 goto redwine
if %input7% equ 2 goto whitewine
[Edit: Correct cure, but no explanation of why the error message appears]
Since input7 is not entered, the if statement is interpreted as
if equ 1 goto redwine
cmd expects if something equ anotherthing dosomething so it sees 1 as the comparison-operator. This is not one of the operators it recognises, so it responds that the 1 is unexpected.
A better form of this is
if /i "%input7%" equ "1" goto redwine
where the /i forces a case-insensitive comparison and "quoting the arguments" preserves the syntax requirement where the user enters nothing or a string containing spaces (you have no control over the user's response.)
I have a script of batch (modeled after Joshua in "War Games")
#echo off
color 0b
echo Greetings, Professor Falken
set /p interface =
echo Would You Like to Play a Game?
set /p ifGame =
if /i "%ifGame%" =="yes" goto yesgame
if /i "%ifGame%" =="no" goto nogame
:yesgame
echo List of Games
echo chess
echo Poker
echo Fighter Combat
echo Guerilla Warfare
echo Desert Warfare
echo Air-to-Ground Actions
echo Theaterwide Tactical Warfare
echo Theaterwide Biotoxic and Chemical Warfare
echo Global Thermonuclear War
pause
echo Which game would you like to play?
set /p WhichGame =
pause
exit
:nogame
set /p areYouSure=Are You Sure?
pause
exit
But, when I enter "No" it still shows the list of games...
You need to remove the spaces between the variable name and the = symbol when using set /p. From:
set /p ifGame =
To:
set /p ifGame=
Otherwise the variable you set has a space at the end of the name. So %ifGame% expands to nothing, whereas %ifGame % will expand to the correct value.