Welcome guest. Before posting on our computer help forum, you must register. Click here it's easy and free.

Author Topic: Batch File Help  (Read 3806 times)

0 Members and 1 Guest are viewing this topic.

Funny204311

    Topic Starter


    Newbie

    • Experience: Experienced
    • OS: Windows 10
    Batch File Help
    « 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.

    Salmon Trout

    • Guest
    Re: Batch File Help
    « Reply #1 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.

    Funny204311

      Topic Starter


      Newbie

      • Experience: Experienced
      • OS: Windows 10
      Re: Batch File Help
      « Reply #2 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.

      BC_Programmer


        Mastermind
      • Typing is no substitute for thinking.
      • Thanked: 1140
        • Yes
        • Yes
        • BC-Programming.com
      • Certifications: List
      • Computer: Specs
      • Experience: Beginner
      • OS: Windows 11
      Re: Batch File Help
      « Reply #3 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".
      I was trying to dereference Null Pointers before it was cool.