Computer Hope

Software => Computer programming => Topic started by: omnominous on November 22, 2014, 11:55:41 AM

Title: goto issues
Post by: omnominous 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  (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.
Title: Re: goto issues
Post by: Salmon Trout on November 22, 2014, 05:31:57 PM
set /p = "place"
What do you think this line does?
Title: Re: goto issues
Post by: Squashman 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.
Title: Re: goto issues
Post by: Geek-9pm 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.
Title: Re: goto issues
Post by: Squashman 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.
Title: Re: goto issues
Post by: DaveLembke 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

Title: Re: goto issues
Post by: Geek-9pm 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.
Title: Re: goto issues
Post by: foxidrive on November 22, 2014, 11:43:55 PM
but if I click enter it goes to the next thing.

click? :)
Title: Re: goto issues
Post by: omnominous 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.
Title: Re: goto issues
Post by: omnominous 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
Title: Re: goto issues
Post by: Geek-9pm 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)
Title: Re: goto issues
Post by: omnominous 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.
Title: Re: goto issues
Post by: Geek-9pm 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.


Title: Re: goto issues
Post by: omnominous 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 ;
Title: Re: goto issues
Post by: omnominous on December 01, 2014, 09:38:46 PM
it is also displaying everything from knock/enter on.
Title: Re: goto issues
Post by: Geek-9pm on December 01, 2014, 11:02:00 PM
You need to define enter at the top of your code.
Don't blame the IF structure.
In batch and in Ch and C you must define or  set variables at the start. With a few exceptions.
As for distribution, Ch is so close to C or C++ that you should be able to compile it and distribute it asa an EXE file after you have the code perfected. But If you want others to help you with it, you can give them the link to the free CH IDE.
Here are three resins I would recommend Ch rather that batch as a general tool.
• It has structure  closer to C/C++ and can be ported to other platforms.
• It is a better learning tool that batch.
• It comes with a nice IDE. (Integrated Development Environment)

But if you want to use batch. bot ahead. Every time you have a IF statement there must be a GOPTO after it. Unless you are very clever.

BTW, there is also Tiny C,which has a very long history. It can be compiled.
http://bellard.org/tcc/
It does very compact x86 code.
Title: Re: goto issues
Post by: omnominous on December 02, 2014, 03:25:37 PM
i defined enter at the top but it is displaying everything like i had said before in the previous reply
Title: Re: goto issues
Post by: Geek-9pm on December 02, 2014, 04:24:00 PM
i defined enter at the top but it is displaying everything like i had said before in the previous reply
I didn't  see it.  Overall, your CH looks good. I still think you will do better in Ch rater than batch. Butch is weird.
Give me some time to run over your Ch code.
Title: Re: goto issues
Post by: Squashman on December 02, 2014, 07:48:58 PM
If you are going to program this in another language then please report this post and ask the moderators to move this thread to that forum category.
Title: Re: goto issues
Post by: Geek-9pm on December 02, 2014, 09:21:36 PM
If you are going to program this in another language then please report this post and ask the moderators to move this thread to that forum category.
My apology for diverting this thread. :-[

I look at the C code the OP had and I see not reason to convert it to batch, other than  the fact that distributing it is more work.
But Ch and Tiny C are freeware programs and can be made available to anyone.

Perhaps the OP will express his preference again.  :)
Title: Re: goto issues
Post by: omnominous on December 03, 2014, 12:19:43 PM
My apology for diverting this thread. :-[

I look at the C code the OP had and I see not reason to convert it to batch, other than  the fact that distributing it is more work.
But Ch and Tiny C are freeware programs and can be made available to anyone.

Perhaps the OP will express his preference again.  :)
  i would like to go back to using Ch because it is an ok program to use.. and i can work on it at school because it is installed on the computers.. well one class.. i wish the library would have it so i can work on it there. i could pull out a 32bit pc and download Ch to my flash drive and use it off of it because i have the 64bit that i use on my flash drive already.
Title: Using Ch as a portable IDE for C pprogrfamming.
Post by: Geek-9pm on December 03, 2014, 12:58:39 PM
The 32 bit version works on any Windows computer. After finding  the error with enter it runs normally. Ch can be installed on a flash drive and run on any Windows PC. For all piratical purposes it is a portable program and does not need to alter the system environment. Provided you put your source code in the same directory.

Glad to hear you school is using an interpreter to teach programming. After about twenty years the schools are now helping students learn tools that are relevant to the current state of the art in the commercial world.

MODERATOR. Can the thread be moved into programming?

Title: Re: Using Ch as a portable IDE for C pprogrfamming.
Post by: Squashman on December 03, 2014, 01:59:38 PM
MODERATOR. Can the thread be moved into programming?
That is what the Report to Moderator link is for.
Title: Re: Using Ch as a portable IDE for C pprogrfamming.
Post by: Geek-9pm on December 03, 2014, 02:18:54 PM
That is what the Report to Moderator link is for.
OK. Did it.
Title: Re: Using Ch as a portable IDE for C pprogrfamming.
Post by: omnominous on December 03, 2014, 02:26:39 PM
The 32 bit version works on any Windows computer. After finding  the error with enter it runs normally. Ch can be installed on a flash drive and run on any Windows PC. For all piratical purposes it is a portable program and does not need to alter the system environment. Provided you put your source code in the same directory.

Glad to hear you school is using an interpreter to teach programming. After about twenty years the schools are now helping students learn tools that are relevant to the current state of the art in the commercial world.

MODERATOR. Can the thread be moved into programming?
the 32 bit version wouldn't work on my 64 bit pc... and there is obviously a problem with the code because it is outputting everything at once after I do 1 and then 1 again...
Title: Re: goto issues
Post by: Geek-9pm on December 03, 2014, 10:24:04 PM
(The OP is now doing his game in Ch, a fast interpreter that conforms to C99 rules. His code now is free of syntax error, but has logical errors.)

I will check the the 32 bit version of Ch on my other machine. I think it should work.
Here is the revised code from the OP. ( sent it via PM)
Code: [Select]
/*File: interactive story*/
#include <stdio.h>
int main ()
{
int house;
int forest;
int poster;
int knock;
int thinking;
int enter;
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.");
            }
        }
    }
}
}

Looks like he has too many left brackets.
Anybody?  :)