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

Author Topic: goto issues  (Read 8001 times)

0 Members and 1 Guest are viewing this topic.

omnominous

    Topic Starter


    Rookie
    • Computer: Specs
    • Experience: Familiar
    • OS: Windows 7
    goto issues
    « on: November 22, 2014, 11:55:41 AM »
    I have recently decided to get into batch files for coding my interactive story so it can be distributed to friends. it seamed easy but it has turned into a stressor. I think I fixed the goto issue but if I click enter it goes to the next thing. anything you can think of wil be helpful.
    Code: [Select]
    @echo off
    :decision
    cls
    echo You are in front of a house, well it is about 5 feet in front of you.
    echo All around you is a empty field besides a forest.
    echo The choices that you are thinking of is either going up to the
    echo house and checking it out, or ending your life some how.
    set /p = "place"

    if "%direction%"  == "house" goto place
    if "%direction%" == "House" goto place

    :place
    echo you walk up to the house.
    echo as you look around more there looks to be some blood on the open
    echo porch next to the rocking chair.
    echo you are starting to think this might be a bad idea.
    echo you hear a noise inside
    echo your only choice now is to knock or enter at free will
    I have other options that you guys probably don't want to see. https://docs.google.com/document/d/1tNlSL2Zb9x-g1-zq14NJ-y8lMYGojVStoeDrgJurXaE/edit?usp=sharing There is the link to see all of it if you want. I have tried everything I can think of.

    Salmon Trout

    • Guest
    Re: goto issues
    « Reply #1 on: November 22, 2014, 05:31:57 PM »
    set /p = "place"
    What do you think this line does?

    Squashman



      Specialist
    • Thanked: 134
    • Experience: Experienced
    • OS: Other
    Re: goto issues
    « Reply #2 on: November 22, 2014, 05:57:25 PM »
    Look at using the /I option with the IF command.
    You are not doing any type of input validation nor do you even tell the user what options they have to enter at the SET /P prompt.

    You may want to look at using the CHOICE command.

    Geek-9pm


      Mastermind
    • Geek After Dark
    • Thanked: 1026
      • Gekk9pm bnlog
    • Certifications: List
    • Computer: Specs
    • Experience: Expert
    • OS: Windows 10
    Re: goto issues
    « Reply #3 on: November 22, 2014, 06:31:32 PM »
    From what the OP said, he already has the program is some other language.  Use of  Batch  as a portable platform is a poor idea. Perhaps the OP would like to explain in more detail why he does not want o use the program in its original form.

    Squashman



      Specialist
    • Thanked: 134
    • Experience: Experienced
    • OS: Other
    Re: goto issues
    « Reply #4 on: November 22, 2014, 06:48:20 PM »
    From what the OP said, he already has the program is some other language.
    Not sure where you see that.

    DaveLembke



      Sage
    • Thanked: 662
    • Certifications: List
    • Computer: Specs
    • Experience: Expert
    • OS: Windows 10
    Re: goto issues
    « Reply #5 on: November 22, 2014, 06:55:10 PM »
    Quote
    You may want to look at using the CHOICE command.

    I have always liked CHOICE for uses like this because of the timer feature where you put pressure on the person to make decisions or else it defaults  by use of the /T switch. I also agree that choice is a good direction to go with your project. I used it a lot in a batch game I wrote in 1997 called Pyramid of Doom which was more of a chose your own adventure book type of game with multiple paths and different endings. I always liked the chose your own adventure books as a kid in the 80s and decided to make a batch version to share with friends.

    Also when using goto statements you will want to use them like below with an escape route such as ( goto Next_Selection1 ) seen below so that they are more like a gosub to bring you back to where you want to be, otherwise it will just continue executing line for line until redirected, and in this case without an escape route it will display all echo'd text:

    Code: [Select]

    @ECHO OFF
    cls
    CHOICE /C ABCD /N /T 100 /D C /M "Select a letter ...  A = Forwards, B = Left, C = Right, or D = Backwards"
    IF ERRORLEVEL 1  goto selection1
    IF ERRORLEVEL 2  goto selection2
    IF ERRORLEVEL 3  goto selection3
    IF ERRORLEVEL 4  goto selection4


    :selection1
    cls
    echo You moved forwards and come to a door with a keyhole that is locked
    goto Next_Selection1

    :selection2
    cls
    echo You turned left and see a long hallway
    goto Next_Selection1

    :selection3
    cls
    echo You turned right and see a painting that seems to be staring at you
    goto Next_Selection1

    :selection4
    cls
    echo You turn around and walk back a few steps back to the location you were
    prior
    goto Next_Selection1

    :Next_Selection1

    @echo.
    @echo.
    @echo.

    CHOICE /C ABCD /N /T 100 /D C /M "Select a letter ...  A = Forwards, B = Left, C = Right, or D = Backwards"
    IF ERRORLEVEL 1  goto selection5
    IF ERRORLEVEL 2  goto selection6
    IF ERRORLEVEL 3  goto selection7
    IF ERRORLEVEL 4  goto selection8

    .....................

    Also this ( goto Next_Selection1 ) is not really necessary at the last text output as for the next thing to do is to give the choices to the user again so this is not necessary, although the path is explicit to following the goto that the others follow after displaying text via echo:

    Quote
    :selection4
    cls
    echo You turn around and walk back a few steps back to the location you were
    prior
    goto Next_Selection1

    :Next_Selection1

    So this will perform the same without the explicit escape path which is not necessary as the last echo listing:

    Code: [Select]
    :selection4
    cls
    echo You turn around and walk back a few steps back to the location you were
    prior

    :Next_Selection1


    Geek-9pm


      Mastermind
    • Geek After Dark
    • Thanked: 1026
      • Gekk9pm bnlog
    • Certifications: List
    • Computer: Specs
    • Experience: Expert
    • OS: Windows 10
    Re: goto issues
    « Reply #6 on: November 22, 2014, 07:34:22 PM »
    Not sure where you see that.
    He siad..
    Quote
    t...to get into batch files for coding my interactive story so it can be distributed to friends..
    Which led me to think he already knows another language and the story might already be in that form.

    foxidrive



      Specialist
    • Thanked: 268
    • Experience: Experienced
    • OS: Windows 8
    Re: goto issues
    « Reply #7 on: November 22, 2014, 11:43:55 PM »
    but if I click enter it goes to the next thing.

    click? :)

    omnominous

      Topic Starter


      Rookie
      • Computer: Specs
      • Experience: Familiar
      • OS: Windows 7
      Re: goto issues
      « Reply #8 on: December 01, 2014, 04:31:07 PM »
      He siad..Which led me to think he already knows another language and the story might already be in that form.
      hey sorry I haven't replied.. I know a bit of C/C++. If you know of a  better portable way of making my interactive story it will be helpful.

      omnominous

        Topic Starter


        Rookie
        • Computer: Specs
        • Experience: Familiar
        • OS: Windows 7
        Re: goto issues
        « Reply #9 on: December 01, 2014, 04:34:53 PM »
        Look at using the /I option with the IF command.
        You are not doing any type of input validation nor do you even tell the user what options they have to enter at the SET /P prompt.

        You may want to look at using the CHOICE command.
        yes It does.. there are 2 to 3 options to choose from

        Geek-9pm


          Mastermind
        • Geek After Dark
        • Thanked: 1026
          • Gekk9pm bnlog
        • Certifications: List
        • Computer: Specs
        • Experience: Expert
        • OS: Windows 10
        Re: goto issues
        « Reply #10 on: December 01, 2014, 06:18:10 PM »
        It he gets tired of use batch, he might want to try Ch. It is an interpreter like C and C++ and can be used interactively to sped development. No comp lie is needed.
        Because it is free and is an interpreter, they is no hassle giving it to others.
        Here is one placer to learn more...
        https://www.softintegration.com/
        An endorsement of CH by a CS prof.
        Quote
        "One of the main obstacles to learning a computer language is learning the things not germane to learning the language. Ch is as close to a perfect teaching environment as I have seen in 20 years for teaching C or C++. I advocate Ch to all of my CS students. If I were in charge of the world, I would require all schools to use an interactive environment such as Ch."
        --- Professor Gene Sheppard, Computer Science, Georgia Perimeter College
        Unlike batch, this little gem has a future. In commercial applications in can be embedded into micro controllers.
        Just saying...  8)

        omnominous

          Topic Starter


          Rookie
          • Computer: Specs
          • Experience: Familiar
          • OS: Windows 7
          Re: goto issues
          « Reply #11 on: December 01, 2014, 08:59:49 PM »
          It he gets tired of use batch, he might want to try Ch. It is an interpreter like C and C++ and can be used interactively to sped development. No comp lie is needed.
          Because it is free and is an interpreter, they is no hassle giving it to others.
          Here is one placer to learn more...
          https://www.softintegration.com/
          An endorsement of CH by a CS prof.Unlike batch, this little gem has a future. In commercial applications in can be embedded into micro controllers.
          Just saying...  8)
          i use Ch and its ok it doesnt really like my if statements. i do
          Code: [Select]
          /*File: interactive story*/
          #include <stdio.h>
          int main ()
          {
          int house;
          int forest;
          int poster;
          int knock;
          int thinking;
          printf("you are in an open forest west of a big abandoned house.\n");
          printf("you can see that the front door is boarded up one window is open\n");
          printf("there is a poster\n");
          printf("if you want to look at poster type 1 if you want to pass press 2\n");
          scanf("%d", &poster);
              if  (poster == 1);
              {
          printf("Welcome to the interactive story of idk!\n");
          printf("\n");
          printf("you can explore a haunted house or a forest in this chapter\n");
          printf("\n");
          printf("you are in an open forest west of a big abandoned house.\n");
          printf("you can see that the front door is boarded up one window is open\n");
          printf("if you want to go into the spooky house press 1\n");
          printf("if you want to go to the forest press 2\n");
          scanf("%d", &house);
          scanf("%d", &forest);
                  if (house == 1);
                  {
                      printf("you are walking up to the white house.\n");
                      printf("you hear a noise inside. do you want to knock or enter? 1 for knock or 2 for enter.\n");
                      scanf("%d", &knock);
                      if(knock == 1);
                      {
                          printf("a big unknown thing breaks down the door and eats you whole. you are dead!\n");
                      }
                      if(enter == 2);
                          {
                          printf("you open the door and see this tall boney grey thing sitting\n");
                          printf("on the floor eating something fleshy.\n");
                          printf("you see a shotgun leaning up against a rocking chair. you are thinking about\n");
                          printf("picking up the shotgun and shooting it or try to reason with it. 1 for reason or 2 for shoot\n");
                          scanf("%d", &thinking);
                      if(thinking == 1);
                          {
                          printf("you say hello and asks what he is doing and it says not a word and rips you in two.\n");
                          printf("bad ending\n");
                      }
                      if(thinking == 2);
                          {
                          printf("you run and grab the shotgun. the big grey thing turns and looks at you as you blow its head off.");
                      }
                  }
              }
          }
          }
          it has a error.
          if(enter ==<== ???
          and
          if(enter == 2<== ???.
          i really dont know.. and with Ch it isnt really portable unless there is a way to patch it up
          and make it distributable like a batch file or something.

          Geek-9pm


            Mastermind
          • Geek After Dark
          • Thanked: 1026
            • Gekk9pm bnlog
          • Certifications: List
          • Computer: Specs
          • Experience: Expert
          • OS: Windows 10
          Re: goto issues
          « Reply #12 on: December 01, 2014, 09:29:32 PM »
          What does this mean?
          Quote
          it has a error.
          if(enter ==<== ???
          and
          if(enter == 2<== ???.
          I did not enter defined in your code.

          I you have a rough time with Ch, do not expect batch to be any easier.
          The IF misstatements Ch are much better than batch.



          omnominous

            Topic Starter


            Rookie
            • Computer: Specs
            • Experience: Familiar
            • OS: Windows 7
            Re: goto issues
            « Reply #13 on: December 01, 2014, 09:32:44 PM »
            What does this mean?I did not enter defined in your code.

            I you have a rough time with Ch, do not expect batch to be any easier.
            The IF misstatements Ch are much better than batch.
            stupid mistake.. kinda like mind the semicolons ;

            omnominous

              Topic Starter


              Rookie
              • Computer: Specs
              • Experience: Familiar
              • OS: Windows 7
              Re: goto issues
              « Reply #14 on: December 01, 2014, 09:38:46 PM »
              it is also displaying everything from knock/enter on.