Computer Hope

Microsoft => Microsoft DOS => Topic started by: Funny204311 on November 19, 2018, 08:43:12 PM

Title: Batch File Help
Post by: Funny204311 on November 19, 2018, 08:43:12 PM
Hello.

I have been trying to code a Truth or Dare bot for a school project.

When you pick truth, you get the option to pick a number between 1-5. This will determine what your truth is.
My problem is that when you pick lets say the number 4, it takes you to first truth instead of the fourth truth. I have been trying to figure out why it is doing this for a fre hours now.

:2PLRTRUTHPLR1ROUND1
cls
color A
echo You picked Truth!
echo Pick a number between 1-5...
set /p 2PLRTRUTHPICKPLR1ROUND1=
if %2PLRTRUTHPICKPLR1ROUND1% == 1 goto 2PLRTRUTHNUM1PLR1ROUND1
if %2PLRTRUTHPICKPLR1ROUND1% == 2 goto 2PLRTRUTHNUM2PLR1ROUND1
if %2PLRTRUTHPICKPLR1ROUND1% == 3 goto 2PLRTRUTHNUM3PLR1ROUND1
if %2PLRTRUTHPICKPLR1ROUND1% == 4 goto 2PLRTRUTHNUM4PLR1ROUND1
if %2PLRTRUTHPICKPLR1ROUND1% == 5 goto 2PLRTRUTHNUM5PLR1ROUND1

:2PLRTRUTHNUM1PLR1ROUND1
cls
echo %Player1%, DARE 1 HERE
pause

:2PLRTRUTHNUM2PLR1ROUND1
cls
echo %Player1%, DARE 2 HERE
pause

:2PLRTRUTHNUM3PLR1ROUND1
cls
echo %Player1%, DARE 3 HERE
pause

:2PLRTRUTHNUM4PLR1ROUND1
cls
echo %Player1%, DARE 4 HERE
pause

:2PLRTRUTHNUM5PLR1ROUND1
cls
echo %Player1%, DARE 5 HERE
pause

If you can help, thanks.
Title: Re: Batch File Help
Post by: Salmon Trout on November 20, 2018, 10:00:11 AM
Please use code tags.

Taking this section as an example... what is supposed to happen after the "pause" command? (That is, after the player presses a key)?
Code: [Select]
:2PLRTRUTHNUM1PLR1ROUND1
cls
echo %Player1%, DARE 1 HERE
pause

I will note that you are storing up trouble for yourself with those crazy long label and variable names. So easy to mistype and so hard to spot the error, and so easy to get confused.
Title: Re: Batch File Help
Post by: Funny204311 on November 20, 2018, 03:07:39 PM
Please use code tags.

Taking this section as an example... what is supposed to happen after the "pause" command? (That is, after the player presses a key)?
Code: [Select]
:2PLRTRUTHNUM1PLR1ROUND1
cls
echo %Player1%, DARE 1 HERE
pause

I will note that you are storing up trouble for yourself with those crazy long label and variable names. So easy to mistype and so hard to spot the error, and so easy to get confused.


I will determine what happens after the pause later, but right now I am trying to figure out why I cant go to lets say 2PLRTRUTHNUM3PLR1ROUND1 when I type in the number 3.
Title: Re: Batch File Help
Post by: BC_Programmer on November 20, 2018, 10:02:40 PM
The %2 (%# being used for arguments into the batch) in %2PLRTRUTHPICKPLR1ROUND1% is interpreted first. so %2PLRTRUTHPICKPLR1ROUND1% becomes PLRTRUTHPICKPLR1ROUND1% which doesn't indicate a variable.

Basic advice is that you shouldn't use digits as the first letters of a variable name. It's possible but it simply becomes a mess.

Ignoring that problem, though- the spaces you have on either side of the == are part of the expressions being compared, so "3 " will never equal " 3".