Sorry your browser is not supported!

You are using an outdated browser that does not support modern web technologies, in order to use this site please update to a new browser.

Browsers supported include Chrome, FireFox, Safari, Opera, Internet Explorer 10+ or Microsoft Edge.

Newcomers DBPro Corner / Game freezing when I try to go to a different section

Author
Message
kp1994
14
Years of Service
User Offline
Joined: 24th Mar 2010
Location:
Posted: 25th Mar 2010 04:40
Hi. I'm trying to program a game for my class, but I'm having some problems.

What I have the game do so far is to first ask your name. You type it in. Then it will ask you if you are sure that this is your name (like a confirmation thing to make sure you didn't spell your name wrong). If you put in the letter y, then it will take you to start the game. If you put in the letter n, then it restarts so you can input your name correctly. If it's neither y or n, then it will tell you that it doesn't understand your response and to type it in again. Here is the code for that:



If you put in y, then it's supposed to take you to the story section, where it tells you the story of the game. Here is the code for that:


The problem I'm having is that whenever I type in my name and it asks for my response, whenever I press y to confirm my name, the game freezes completely and I'm unable to do anything else. If I hit n, then it goes back to typing in your name like it's supposed to. Also if I press something other than n or y then it'll tell me that it doesn't understand, also like it's supposed to. It's just the y function that's messing up. Can anyone tell me why it's doing this?
TDK
Retired Moderator
22
Years of Service
User Offline
Joined: 19th Nov 2002
Location: UK
Posted: 25th Mar 2010 16:11
Using Goto to jump around your program like that creates what is known as 'spaghetti code' - for obvious reasons. It's also the most likely reason your program is freezing as you have no proper program flow control.

In short, you are probably jumping to the wrong place, and not coming back afterwards.

That way of programming is asking for trouble. Nothing is ever going to work properly and fixing problems will always be a nightmare until you give your programs the proper layout.

I'm sure you don't want to hear this, but you need to get back to basics.

Learning a programming language is like learning a language like German, Spanish or Chinese. With both types, you HAVE to learn the elementary building blocks first.

It's like you are trying to write a book in Chinese but you haven't learnt the alphabet fully yet - it just won't work.

You need to read tutorials 1 to 4 here before going any further:

http://forum.thegamecreators.com/?m=forum_view&t=99497&b=10

They will tell you how to create a modular template and do tasks with subroutines and functions instead of Goto.

TDK

HowDo
21
Years of Service
User Offline
Joined: 28th Nov 2002
Location: United Kingdom
Posted: 25th Mar 2010 19:08 Edited at: 25th Mar 2010 19:09
What TDK say above it very true, you will be writing code the right way very soon.

Now the above code stops when you press y, beacuse you have jumped to a do loop(StorySection: ) however theres no sync to update the screen, also there no way for it to break out to do the next bit of code to check what key has been pressed.

hope that help in seeing where its not going.

try F7 this will show it doing this.

Dark Physics makes any hot drink go cold.
kp1994
14
Years of Service
User Offline
Joined: 24th Mar 2010
Location:
Posted: 26th Mar 2010 05:36
Thank you for your help. I'm sorry for any complications or irritations that I may have caused. This is for my Video Game Development class, so I really am a beginner.

Thank you for the suggestion to the website's tutorials, because the tutorials at my school only showed me how to use simple commands like do/loop and for/next. I never learned anything about 'spaghetti code' or how the goto command could be used incorrectly. The site's tutorials have a lot more commands and how-tos that I have not learned about, so again, thank you.

Login to post a reply

Server time is: 2024-11-27 13:21:09
Your offset time is: 2024-11-27 13:21:09