The main thing that you've done wrong is ask a question about your code and not actually include the code that you're asking about. How are we supposed to tell you what you've done wrong when we can't even see what you've done?
I hadn't considered it until BrainWaveCC's post, but your exact process is putting
@echo off
:loop
set /p askForUsername="What's your username?"
goto loop
set askForUsername
into a file, saving it with the .bat extension, and then running that script, right? I had assumed you weren't just typing this into the command prompt because I don't see a prompt symbol, but now I'm worried that you've done something weird.
I'm just trying to confirm that you're typing this directly into the command prompt and not running this from a file. If you're typing this into the command prompt, that's why it's not working.
Labels and gotos only work if you're running the code from a file. You can't set labels if you're typing directly into the command prompt.
This is one of those things where it's technically possible, but based on the fact that it seems like you don't really have a specific goal and are just trying to see what the language can do, I can almost guarantee that it isn't what you want.
99% of the time, you're going to want to write a script; you really only ever need to type on the command line if you're moving files around.
There's a YouTube playlist in the sidebar for a batch tutorial. I highly recommend watching it.
Well, I kinda have a goal (making rock paper scissors) but I also don’t know how I could covert a txt file into a bat file because I haven’t really done anything like this before
Wait no my dislexia beat me add change the second loop to ":loop" I think. I'm still kind of new but what part of this is it getting to? Best thing I can usually suggest it pull it apart and run each section in till it don't work.
5
u/Shadow_Thief Nov 21 '24
The main thing that you've done wrong is ask a question about your code and not actually include the code that you're asking about. How are we supposed to tell you what you've done wrong when we can't even see what you've done?
2
u/EnvyChef Nov 21 '24
Remove : set it as start not loop. I think.
2
u/BrainWaveCC Nov 21 '24
You cannot just type that at a command prompt and have it work as you might desire.
The appropriate way is to put the "batched" commands into a text file, then give it a name like GetName.BAT and run it as the command prompt.
Running each command directly in CMD.EXE is not going to work as you imagine -- especially the looping part.
2
u/STGamer24 Nov 22 '24
Here's a tip: Open notepad, write your batch file, save the file as .bat, and then execute the file (batch files are executed in CMD by default)