Jump to content
  • Advertisement
Sign in to follow this  
theadamSGT

goto

This topic is 4843 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

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?

Share this post


Link to post
Share on other sites
Advertisement
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?

Share this post


Link to post
Share on other sites
[qoute]Couldn't you just call another function or something like that?[/qoute]
i heard of calling functions but how do you do it

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites
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 it

int 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

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!