Skip to main content
GameDev.net gamedev.net
🔒 Locked

goto

Started by theadamSGT Aug 10, 2005 at 2:08 PM 16 replies 1.2k views
Original Post
theadamSGT
theadamSGT
how do i use goto for my text game i know i shouldnt but it looks like it would be easier. like having area1 area2 then using goto area1 how would i do this?
ukdeveloper
ukdeveloper
Quote:
Original post by theadamSGT
how do i use goto for my text game i know i shouldnt


You certainly shouldn't. It will just make your code unreadable and your program's operation unpredictable. It should only really be used in controlled circumstances i.e. bailing out of a loop.

What exactly are you trying to do in your text game? Couldn't you just call another function or something like that?

mercurium
mercurium
You just create a label like this:

stop:

and go to it with this:

goto stop;
Still 2^10 :P
theadamSGT
theadamSGT
[qoute]Couldn't you just call another function or something like that?[/qoute]
i heard of calling functions but how do you do it

kingnosis
kingnosis
Assuming C/C++, first define your function:
void Area1() {  // do something}


And then to call it, use this:
Area1();
Sneftel
Sneftel
theadamSGT, you really, really, REALLY need to get a book on your chosen programming language. Trust me: learning a bit at a time by posting questions on forums is not going to work.
theadamSGT
theadamSGT
i knew that that kingnosis i just didnt know what calling functions was.
but i think i will try it.
i will post my qeustions as i get to them thanks everyone.
Maledict
Maledict
I just want to add a little bit on calling functions -- arguments (Basically, giving the function data).

So basically, here's a sample function prototype for how to use arguments,
int Area1(int a, int b){// do stuff}


And when you call it, you'd do this,

 Area1(a, b); // you can pass it any two values, as long as they're integers


So you're giving it values, so you could do something like this (simple usage of functions)

#include <iostream>using namespace std;int Area1(int a, int b); // function prototypes to allow functions declared before                         // the caller to know about itint main(){   int a = 5;   int b = 7;   cout << Area1(a, b); // you're giving the function values of a and b   cin.get();   }int Area1(int a, int b){ // the variabels can be anything in the prototypes   int c = a + b; // adds the values of a and b LOCAL to that function                  // it doesn't affect the original variables in main   return (c); // gives back value to output}


The code is working, so you can play with it a bit, to get a good feel for functions.

If you want, I could go over passing by reference as well.


Hope I could help!


Maledict

theadamSGT
theadamSGT
i know functions very good already so i dont need any examples of functions unless its advanced functions.
ukdeveloper
ukdeveloper
Quote:
Original post by theadamSGT
i know functions very good already so i dont need any examples of functions unless its advanced functions.


[rolleyes]

(No offence intended below)

What do you mean by "advanced functions"? You can make your own functions, they can be as simple or as complex as you please.

And if you "know functions very good already", why are you asking about how to call them?

I agree with Sneftel - get a book.

It will help you in your quest to learn C++ (it seems to be that you're learning).

Good luck!
Coz
Coz
It's not that it's not going to work. It's that you are gonna waste your time doing so.

1st, it's not going to be easier, because since you will have trouble with the things that seemed easier you will have to learn the right way anyways.

2nd, when you ask people you have to wait for them. Also, you don't even know if you are gonna have the information you need.

I feel you would be like 5 times more efficient by doing things on your own, and when you are stuck in a way that you have tried almost you can think about and you have wasted more than 1 hour thinking, then you can look for help as a last resort.

It seems you know some, but you aren't sure how much you know. If you read a book that teaches you about the programming language syntax, and learn from it, you can have an aproximated value of your knowledge.
theadamSGT
theadamSGT
[qoute] if you "know functions very good already", why are you asking about how to call them?[/qoute]

sorry about that i meant what is calling them not how do i call them. and forget what i said about advanced functions. i cant remember the names of stuff good but i can do the stuff and i do have a book
i got to pointers it took me a while to understand them it took me about 5 days to understand them so thats why im not that good yet. you guys dont have to reply to this thread now im going to try making my text game now but i have one qeustion i dont have my book with me right now so i cant check it out but could someone post an example of the if else statement i forgot how to do it i just need one little example.
Maledict
Maledict
if (x > 10)
{
cout << "X is 10" << endl;
}
else if (x < 10)
{
cout << "X is less than 10" << endl;
}
Maledict
Maledict
Anytime, if you need help with anything, don't hesitate to PM me.


Maledict
theadamSGT
theadamSGT
okay thanks could you pm me just so i can remember your name?
MSalley
MSalley
Quote:
[qoute]Couldn't you just call another function or something like that?[/qoute]


Heh heh...


Anyway, you sound like me two months ago. I started a thread about the exact same thing. Don't worry, it gets easier. Keep pluggin'.

-Mat² §alley©-

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.