I wanted to make this script work somehow, but i find that after you use
set /p variable= whater you want here
If you use the echo command after it, its hidden or something because it wont come up...
#echo off
cls
color A
:MAIN
cls
echo.
echo.
echo =================================
echo. set /p var= what is your name?
:: DOES NOT SHOW UP (STARTING HERE)
echo.
echo =================================
:: DOES NOT SHOW UP (ENDING HERE)
set /p answer= so your name is %var%?
IF %answer%== yes echo thats an amazing name!
IF %answer%== no goto MAIN
The part thats surrounded by the remarks doesnt want to show up for some reason... any ideas?
If I'm understanding what you are trying to do, this is the code you need:
#echo off
cls
color A
:MAIN
cls
echo =================================
echo what is your name?
echo =================================
set /p var=
set /p answer= so your name is %var%?
IF [%answer%] == [yes] echo thats an amazing name!
IF [%answer%] == [no] goto MAIN
pause
Because the processor will wait for the user input after printing what is your name? (due to the /p), you will not get the next line of ========etc. until enter is pressed.
It shows up for me, I get
=================================
set /p var= what is your name?
=================================
so your name is ? Andy
Which is what I would expect, what are you expecting?
Related
I want the line of code below to work or something that will do the same and i want the echo and echo. to show befor i press any key
set /p variable=
echo.
echo test
echo.
echo test
::ect
and I want the line of code below to work or something that will do the same and i want the echo and echo. to show befor i press any key
pause
echo.
echo test
echo.
echo test
::ect
I tried this (I have not tried it with pause)
#echo off
for /f %%A in ('echo prompt $E^| cmd') do set "esc=%%A"
cls
echo *other text*%ESC%[2A
set /p variable=
echo %ESC%[1B
I was only able to have one echo or one echo. after set /p variable=, but I expected to be able to have multiple echo below set /p variable= and multiple echo. below set /p variable=
If i try to have more then one line of text then it takes the line of text above set /p variable= and moves it down below set /p variable= and combines it with the text i want below set /p variable=
So i want the set /p variable= and pause to pause after all the echo and echo.
I want it to look like for example this when i open the .bat file
Type the number of your choosing:
*other text*
Or this
Press any key to continue . . .
*other text*
sorry for posting the same thing so many times i promis that this is the last time
You are using ANSI escape codes. Just use them at the right place and with the proper parameters (numbers):
#echo off
for /f %%A in ('echo prompt $E^| cmd') do set "esc=%%A"
cls
echo/
echo/
echo *other text*
echo *additional text*
echo *some more text*
echo %ESC%[5A
set /p "variable=Enter var: "
echo %ESC%[2B
echo Thank you for your input.
Output on screen (where Hello is the manual input:
Enter var: Hello
*other text*
*additional text*
*some more text*
Thank you for your input.
You need enough space "above" set /p. It doesn't work at the very first line (after CLS) because you can't move the cursor to "line zero", so you need (at least) two (empty) lines (echo/).
So recently I started learning Batch-file, and today I decided to try and make a game with it. I have a few errors, and can't figure out what is wrong with the code.
Heres the code:
#echo off
title Batch Rpg
color 07
echo Welcome to Batch Rpg!
echo.
echo.
pause
:menu
cls
echo.
echo -Menu-
echo.
echo.
echo.
echo 1) Begin
echo.
echo 2) How to play
echo.
echo 3) Exit
echo.
echo.
echo.
echo ---------
echo.
set /p c=Choice:
if %c%==1 goto prestart1
if %c%==2 goto howtoplay
if %c%==3 goto cfr_exit
if NOT %c%==1 if NOT %c%==2 if NOT %c%==3 goto menu
:cfr_exit
cls
echo.
echo Are you sure you want to exit?
echo.
set /p c=(Y/N):
if %c%=="Y" exit
if %c%=="N" goto menu
if NOT %c%=="Y" if NOT %c%=="N" goto cfr_exit2
:cfr_exit2
cls
echo.
echo You must enter a valid option.
echo.
pause
goto cfr_exit
:howtoplay
cls
echo.
echo -How to play-
echo.
echo.
echo.
echo This game is very simple. There will be a number with an option after it, type the option in and it will perform an action(As the option would say).
echo.
pause
goto menu
:prestart1
cls
echo.
echo Welcome to land of Fageryth!
echo.
echo What is your name, adventurer?
echo.
set /p playername=Name:
goto prestart2
:prestart2
cls
echo.
echo What would be your more valued statistic, Attack damage, or Hit points?
echo.
echo.
echo.
echo 1)Attack damage(Atk)
echo.
echo 2)Hit points(Hp)
echo.
echo.
echo.
echo ---------
echo.
set /p playermorevaluedstat=Choice:
if %playermorevaluedstat%==1
set playeratk=6
set playerhp=25
if %playermorevaluedstat%==2
set playeratk=4
set playerhp=30
if NOT %playermorevaluedstat%==1 if NOT %playermorevaluedstat%==2 goto prestart2
cls
echo playeratk
echo playerhp
pause
I'm having trouble with the :prestart2 section of my code. With the end of it, I tried to make it where if the variable wasn't equal to 1 or 2, which were the options, then it send the player back up to the start of the section again, and also, when it finishes checking, I'm trying to make it display the two variables playeratk and playerhp but instead it just closes out. I am really lost here and would appreciate the help!
A couple things before we start:
First, when troubleshooting your batch scripts, get rid of (comment out) your echo off and cls lines so that you can see where it's going wrong.
Second, you should always double-quote your variables to make sure you're not inadvertently including spaces when setting and comparing them. It doesn't seem to actually be causing problems in your code, but it's a good habit to get into:
set "var1=something"
set "var2=a string with spaces"
if "%var1%"=="something" echo %var1%
Now, the problem in your code is with the two if statements stretching over multiple lines. If you're going to do that, you have to put them inside of parentheses.
set /p playermorevaluedstat=Choice:
if %playermorevaluedstat%==1 (
set playeratk=6
set playerhp=25
)
if %playermorevaluedstat%==2 (
set playeratk=4
set playerhp=30
)
I want to make a batch adventure game (not text-based adventure) that gives you options and lets you choose to progress the story.
Problem is I don't know how to save or load progress in the game and I want to make (possibly) multiple accounts you can access to start where you left off.
I know it's possible, since I've seen it in a batch game (who's file I lost). So, anyone know to make it possible?
#echo off
:menu
cls
echo 1.Sign in
echo 2.Register
echo 3.Exit
echo.
set /p input=What would you like to do:
if %input%==1 goto log
if %input%==2 goto reg
if %input%==3 goto exit
goto menu
:reg
cls
set /p user=Enter your desired username:
set /p pass="Enter your desired password:
echo %pass% >> %user%.txt
:: This will prompt for a username and password and then
:: output the user variable as the name of a .txt file that contains the
:: password
goto menu2
:log
set /p user="Enter your username: "
set /p pass="Enter your password: "
set /p password=<%user%.txt
pause >nul
:: This will check if the password entered is equal to the password in
:: the .txt file
if %pass% equ %password% goto menu2
goto menu
:menu2
::Enter your script here
The system is much shorter when you get rid of the comments. :)
Later on in your game you could use the same system as used in the :reg label to create a batch file with player stats and maybe an inventory in it such as set /a armor=2 and set /a sword=1 then call on that file when you want to show the player their statistics/inventory. Just an idea... Anyway, hope this helps at least a little bit.
Im making a game and this is the login signup this is part of the code
#echo off
color f
:logsign
title whattodo?
cls
echo What will you do?
echo.
echo 1) Login
echo 2) Sign in
echo 3) Exit
echo.
set /p web=Type 1 or 2?
if "%web%"=="1" goto login
if "%web%"=="2" goto signup
if "%web%"=="3" exit
:notvalid
echo you're username is not valid.
echo.
echo please try again or sign up.
pause
cls
goto logsign
:notvalid1
echo you're password is not valid.
echo.
echo please try again or sign up.
pause
cls
goto logsign
:signup
title Sign Up
cls
echo What will be your username?
echo.
set /p username=Username:
echo %username% >%username%.bat
cls
echo What will be your password?
echo.
set /p password=Password:
echo %password%>>%username%.bat
cls
echo Go back to log in menu then log in.
pause
cls
goto logsign
:login
title login
cls
echo Let's start with name.What is it?
echo.
set /p username=Type username:
if not exist %username%.bat (goto notvalid)
pause
cls
echo Now what is your password?
echo.
set /p password=Type password:
if not exist %username%.bat (goto notvalid1)
pause
goto home
The sign up saves the user and pass in a .bat file
possibly you could save stats to a file named after the player profile and read off of that file to see what level they where on look around over here.How to read file contents into a variable in a batch file?
i'm new to the coding of batch files and got an error wich i can not solve..
the problem occurs at the :secName , I made a printscreen at the flash(just before it exits cmd), and it said: "so your name is [what %name% is]"and then "the syntax of the command is incorrect.
goto was unexpected at this time."
i've got this coding done now:
#echo off
goto Welcome
title The Game Of Everything
:welcome
echo.
echo Welcome!
echo What is your name?
set /p name=Enter:
goto secName
:secName
cls
echo.
echo so your name is %name%?
set /p secName:yes or no?:
if %secName%== yes goto begin
if %secName%==no goto welcome
:begin
cls
echo.
echo Welcome %name%, to "The Game Of Everything"!
echo I hope you enjoy this mini-game, downloadable on your computer!
echo.
echo It isn't the prettiest, but who gives a toss right?
echo press any key to continue...
pause>nul
exit
change this:
set /p secName:yes or no?:
to this
set /p secName=yes or no?:
I'm trying to make a program like clever bot but when the uses spaces it won't work. Please help.(:
#echo off
set text=Hello
:start
cls
echo %text%
set /p input=:
if %input%==a b set text=It worked
goto start
Use quotes:
#echo off
set text=Hello
:start
cls
echo %text%
set /p input=:
if "%input%"=="a b" set text=It worked
goto start
It will also handle null input.
Mona