How do you ask the user for their name, not using %USERNAME% or something, but just asking for their input, then drawing a reference to that later.
This is my core so far
echo Who are you?
set /p Name = Enter your name:
set name= %Name%
echo Hello %name%
pause
goto WakeUp
:WakeUp
echo Who are you?
set /p Name=Enter your name :
echo Hello %name%
pause
:WakeUp
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/).
I've seen in batch code that you can ask for user input on a separate line or continue while asking or something. For example it would look something like this;
enter your name
name:_(input would be here)
enter name above
And the code might look like;
echo Enter your name
set /p /(continue) name=name:_
echo enter name above
Or maybe:
echo enter your name
(line 2)
echo enter your name above
set /p /line:2 name=name:_
#echo off
setlocal
cls
echo enter your name
echo name:
echo enter name above
rem Move cursor to one line below screen size,
rem you must adjust this value to fit your screen.
for /L %%i in (1,1,34) do echo/
rem Move cursor to screen home and hide timeout "Waiting..." message
for /F %%a in ('timeout /T 1 ^> CON') do rem
set /P "name=name: "
echo/
echo/
echo/
echo Name read: "%name%"
Further details at this post
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 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?