-1

I am trying to just make a casual conversation using notepad as a batch file creator but whatever I search and try, it keeps saying the syntax of the command is wrong.I was just making it and went to test it and it came up. I have tried doing other stuff on different lines and then set /p ... but it never works. What am I doing wrone; I just want to continue on my just-for-fun project. Thanks:

%echo off
set /p name="Hello, what's your name?"
set /p S?1="Oh, well: hello %name%! Is that what you would like me to call you? (Y/N)"
if /i "%S?1?%" EQU "Y" goto :Yes
if /i "%S?1%" EQU "N" goto :No
goto :No answer
:Yes
echo Okay! Just making sure so I do not get on your nerves!
goto :Next1
:No
set /p name="Oh, then what shall I call you, then?"
echo Oh, alright. I will cal you %name% from now on! Sorry.
goto :Next1
:No answer
echo Sorry, but I do need an answer.
timeout 1
:No answer again
set /p S?2=So, is that what you would like me to call you? (Y/N)
if /i "%S?2%" EQU "Y" goto :Yes
if /i "%S?2%" EQU "N" goto: No
goto :No answer again
:Next1
pause
aschipfl
  • 33,626
  • 12
  • 54
  • 99
sirfused
  • 21
  • 1
  • 1
  • 7
  • `%echo off` should read `@echo off` finally; however, for debugging, you should remove this line to see what strings your variables become expanded to and what lines of code are actually executed; in addition, do not run the batch file by double-clicking its icon; instead, open a new command prompt window, type the (path to the) batch file and press enter, so the window remains open, showing any potential error messages... – aschipfl Oct 25 '16 at 11:16
  • I do not really understand what you are talking about as I am just a newcomer to code but also, this does not answer my question. Do not worry, though: I have it sorted now! Thanks for at least trying to help me, I do appreciate it. – sirfused Oct 28 '16 at 17:16
  • My comment is not an answer, I tried to help you to debug your code: 1. press _Win_+_R_, then type `cmd` and press _Enter_, so the Windows Command Prompt window appears; type the (quoted) full path to your batch file into it (e. g., `"C:\My Scripts\test.bat"`), then press _Enter_ to run it; when it has finished, the window remains open, showing the output of the batch file; double-clicking the batch file in Windows Explorer lets the window close after execution, so debugging is quite impossible... – aschipfl Oct 28 '16 at 17:27
  • 2. as long as there is no line `@echo off` on top of your batch script, every single line/block of code is echoed (output) in the command prompt window, with all the variables like `%VAR%` replaced by their actual values; this helps a lot for debugging; as soon as your script works, you may want to prevent it from echoing each command, so put `@echo off` in the very first line... – aschipfl Oct 28 '16 at 17:28
  • Oh, sorry then. It is just the error messages are not quite detailed and this way will just take that tiny bit longer, so I will continue to double-click. Thanks, though. – sirfused Oct 28 '16 at 17:29
  • Oh, well in my opinion that kind of just makes it confusing in a way that I cannot think off how to explain, sorry. – sirfused Oct 28 '16 at 17:32
  • As you can see, I have edited my code but added some bits and where sees if the age is less than or greater than an age, it says the syntax is wrong... Can you spot my mistake? (It can be found in a new post, I will add link in a second) – sirfused Oct 28 '16 at 17:59
  • http://stackoverflow.com/questions/40310920/trouble-with-less-and-grea-excetra-if-commands – sirfused Oct 28 '16 at 18:13

1 Answers1

2

Get rid of the extra question mark on line four, (typo).

Then change your labels.

Labels are single strings without spaces, so some of them are returning to :No because it sees "No", "No Answer" and "No Answer Again" as the same. I'd suggest you change them perhaps to :No, :Answer and :Again.

Compo
  • 36,585
  • 5
  • 27
  • 39
  • Ah. Just came to check my post to see if I had any replies and also to edit it as I got it fixed, but I was just about to add another post asking what is wrong with my Yes answer bit as even when I added Y it just went to :No, so thanks! I will likeley post again later if I struggle again as I am just about to continue. – sirfused Oct 28 '16 at 17:19
  • I am about to make a new post for another error, I will add link soon but could you see if you can solve it? Thanks! – sirfused Oct 28 '16 at 18:01
  • http://stackoverflow.com/questions/40310920/trouble-with-less-and-grea-excetra-if-commands Thanks – sirfused Oct 28 '16 at 18:14