trying to return to the beginning of the program....

0 John Tompson · July 29, 2015
i have studied this c language and find no way to get BACK to the beginning of a program.

create character hero
walk around {infinite until life==0}
[don't want the program to end after making 1 step into a dungeon]: need to explore the rest of the map. data 1,1,2,1,1,1,1. read data. get a$. map(x,y). A$="hero's name"

need to return to the walk around section.
500 lines of code and 3 other loops separate needing to return to this section.
don't know how to do this without a "goto 10": ?"this is not possible with the 'continue' command...": A$="this c language is not that good of a language and takes more space (?print){}()"" to write and in program size)".

?"do you know how to solve this problem?";get how$

::i don't see how it is possible to fit 500 lines of code and 3 separate loops within a single "do while" or "if else" statement.
when a sample was run for mixing a for and if statement together for example, it completely ERASED the values of all of my variables within these brackets........



Post a Reply


- page 2
Oldest  Newest  Rating
0 Saket Kulkarni · August 21, 2015
Hey Guys,

In all these forum discussions, you seemed like the C-Gods to me.... I'm just a newbie....

So, did u guys learn C from Bucky's tuts(which are freakin' awesome acc. to me...) and den go for advanced C courses elsewhere? Just need-to-know stuff so that I can be a pro like u guys 1 day(Hopefully soon!!)

0 John Tompson · September 2, 2015
hi jon,
nice to hear from you!

yes, i agree. you said to keep it "simple and clean" and "to keep them more organized"; so that is why i said header file. keep you program simple. all extra data is in the header files.
->okay, so it doesn't matter if the break is in an if statement, as long as it is within a do while. -->>SUCCESS
didn't realize that you could use it in an if statement. well, without a do while you cant use a break in a if. thanks!!!

#include <stdio.h>
#include <stdlib.h>
//i am putting all my data and void functions in a header file to clean up and simplify this program
//#include <headerFile.h>

int main()
    int turns =1000;
    int toDo = 1;
    int fight = 4;
    int run = 2;
    int takeANap = 3;
    int exit = 1;
    char action[20];

    do {
        printf("\n player takes their turn\n");
  //ask what to do
  if(toDo == fight){
        action[20]= "fight";
  printf("\n player fights a monster");
printf("\n\t player does not run");
printf("\n\t player does not stand there looking around as monster is beating him up");}

  else if(toDo==run) {
   printf("monster is gone");}

  else if(toDo==takeANap){
   printf("the earth is healed +1 HP");}

  else if(toDo==exit){
        printf("\n the world has ended and you stood around and did nothing");
   } while (turns!=1000);
  printf("\n program ends\n");

    return 0;

0 John Tompson · September 2, 2015
hey there c student:angel:
thanks for getting back to me.

1. do you know where i can look at c game code: how to find it so i can learn and get better **{from examples}&; && || model code.

yes, everyone can always learn more.
however, the sticking point is not the specific details, but rather the lack of possibility and probable error in the c language code itself, as the program always goes forward, but cannot go back: therefore the entire program is one giant loop with a bunch of other loops in between. as soon as you end the big loop, the program ends -- it doesn't keep going, nor can you get "back" into the loop. so i am trying to figure out a strategy to do this. i figure that i will use a model similar to what you have shown though.
the other difficulty is the lack of compatibility in the c language code for built in c language functions.

i really like how you simplified it though. you simplified it even further than i had been planning to do. i like that idea.
i didn't know that you could fetch a keyboard input outside of a for loop.

the map is a long rectangle because when i look at the code, the map will fit all on the same line, in that i can navigate the map with my eyes (and so i can see if there are any errors).
but i can fit more digits on the screen with c, so my map can be bigger (for the first peice {will add a bunch of peices together}): otherwise i risk error and a hero runs into a dead end and cannot complete the map {if there is an error}.

so with the sample game architecture that i have included, the entire game where a player will play for 100 hours is run with a single do while loop with 6 sub loops within a single loop.
//possible error: if i cannot find a way to implement this, then i will not be able to get back to (no goto) the "encounter monster section" (as the program keeps going forward and cannot go back several lines), unless i manually write 1000 encounter monster sections (as a single game does not have more encounters than this). or a do while within a do while loop. or a for statement with a do while inside of it (assuming this is possible): as in for turns = 1 to 100000; {{do (if encounter) {fight} while...}} next i (end for statement, i++)...

#include <stdio.h>
#include <stdlib.h>
#include <variables.h>
#include <mapData.h>
void print new coordinates of map on screen
main void fetch keyboard command

int main()
roll hero stats
      {if new hero->
          save temp hero stats
begin game
print map on screen
      {//fetch keyboard command
      {if xy!=same->
          walk across map
          //print new coordinates of map on screen
encounter monster
      {if monster->
          hit, miss, miss, hit
      {if earth HP==0
          hero killed;
defeat monster
gain treasure an XP
hero wins
      {if hero win->
    return 0;

friend programmer,

0 John Tompson · September 2, 2015
hi saket,
nice to meet.


awesome dude. i'd like to talk to bucky. he asked for advice on one of his tutorials and i was going to help him.
but he's so popular, why would he talk me? no one knows me and i'm not a pro at programming, and i know less than 4 programming languages.
anyways, i don't know HOW to talk to him, assumming he wasn't too busy to do so.

yes, i watched ALL of the tuts, some of them twice for review. but i have not read the book yet. guess that is the next step...
i'm not lookin to be a pro, just write my own game programs (think i'll shy from c# as it takes too long for 1 person to complete *{graphics}), and to get a good computer job (though it probably wont be as a programmer because i don't want to get carpel tunnel (unless a speech to text is allowed, and then i would take a programming job).
i want to be successful in life someday. tired of flippin burgers in the fast food joints.

0 c student · September 2, 2015
games arent usually programmed in c, at least, not very complex ones.  most games are done on c++ and also java, however, they might include techniques such as classes to maintain their code.  if you're not familiar with these things then it might be a bit hard to understand how games of such complexity are done.  there are many simple games done in c and a quick google search for the source codes should point them out.  the only decent game i know of that was coded in c is doom.
0 John Tompson · September 9, 2015
c student, glad to hear from you!

that was an awesome game. it is definitely a classic. there is nothing wrong with that game.
yes, i don't mind writing a simple game. the reason why i wasn't going to use c++ is because i wanted to master c first. 
then i will learn c++. however, i figured that i didn't need c++ because that is mostly for high end (take a long time) graphics.
a simple game is fine; otherwise, for a high end game it takes 100 people to make it, so if i am going to make it myself,
it is okay for it to be a simple game (because it will take a billion years for a better one).

so you say there is more program code available for c++, when it comes to looking at examples?
thanks for the advice.

1. but as far as the program architecture, what do you think of the "structure" of my program that i have shown you in the previous post?

  • 1
  • 2



One of the most popular languages of all time.

Bucky Roberts Administrator