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.

Author
Message
Game Programer to be
16
Years of Service
User Offline
Joined: 12th Mar 2010
Location: TX
Posted: 12th Mar 2010 14:21
Ok I am only 16, and into a video game development class. I wouldn't know what your talking about if you go way over my head. My menu doesn't want to work a second time. I have the main menu and then a newgame menu. If you guys can tell me what I did wrong in my coding or if something is missing please let me know.

------------------
Harley
Hawkblood
16
Years of Service
User Offline
Joined: 5th Dec 2009
Location:
Posted: 12th Mar 2010 19:01
First off, try to make functions instead of doing gosub and goto. They work fine for some things, but I can't see where you would need them here.

gosub is something that must return to the spot it left from. It's not practical here.

Your program is linear and you want a non-linear type. Make a main loop and call the different menu functions from there:
psudo-code:


Remember, if you want a function to return a value just place the variable after the "endfunction" statement.

Your problem with it not going back may be related to the gosub's and goto's...

The fastest code is the code never written.
acurrate eye
16
Years of Service
User Offline
Joined: 28th Aug 2009
Location: ur house under your pillow was under bed
Posted: 13th Mar 2010 17:42 Edited at: 13th Mar 2010 17:45
You can use funtions but u can also use gosubs here's and example of what i do for my games i make also u will need arrays for it this is a rough draft you can find the tut on youtube
"how to make a menu using gimp in dbpro". I think is the name for it




This is a rough draft. but you are better off using what hawkblood says in what your trying to do

if you can't do it try try again and if you still cant do it ask for help
TDK
Retired Moderator
23
Years of Service
User Offline
Joined: 19th Nov 2002
Location: UK
Posted: 15th Mar 2010 06:18
Quote: "try to make functions instead of doing gosub and goto"


Not using Goto I agree with wholeheartedly. Please, please, please, pretend it does not even exist. It's a throwback to the old days when programming languages didn't have procedures or functions and has been left in only as a legacy command. Don't use it. Period.

Besides, there's probably nothing you will ever want to do that you can't do without subroutines and functions.

But, I have to disagree with using functions rather than using Gosub.

Yes, of course you could write a program which uses absolutely no subroutines - only functions. The question is why on earth would you want to do it?

Functions have their uses, but they should be used when using them has a clear advantage over using subroutines. Speed isn't one of them.

Variable scope in functions (local variables) can be both an advantage and a disadvantage. You have to declare lists of global variables - or pass parameters to functions and then you can only get one variable back. If your global variable declaration list is extensive, then why wouldn't you use a procedure?

A subroutine can automatically see all the variables in your program and any changes it makes to them can be seen by the program when it returns.

Where functions are really useful is where you only want a single value returned, as you can then include it in a condition. For example, you might have a function called InTheBox() which determines if a mouse click is within a region of the screen, returning True if it is and False if it isn't.

A function allows you to use:



You couldn't do that quite as concisely with a subroutine.

So, in a nutshell, I am simply saying that it's no bad thing to mainly use procedures and use functions only when they make your life easier.

As for your menu problem, check out the tutorial on menus (number 16) here:

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

TDK

SoftMotion3D
AGK Developer
20
Years of Service
User Offline
Joined: 24th Aug 2005
Location: Calgary,Alberta
Posted: 15th Mar 2010 08:23
Humm.... i disagree! lol

I dont mind using spegettie code myself... i use gosubs,goto's all over the place instead of using functions.

Personaly if your new at coding its easier to learn i think.
Functions are pritty much the same as gosubs,returns

whats the difference from using functions to using gosubs?
Maby the code looks easier to follow....keeps it looking cleaner i guess.

One thing to avoid however.... (for x loops) as much as possible.
Too many of these inbetween loops will kill your performance quickly. Of coarse in most cases you need them but id try to limit how big they are. Everytime my programs slow down.....thats the first thing that needs to get shortened or removed.

Development & Editting
TDK
Retired Moderator
23
Years of Service
User Offline
Joined: 19th Nov 2002
Location: UK
Posted: 15th Mar 2010 18:01
Quote: "I dont mind using spegettie code myself... i use gosubs,goto's all over the place instead of using functions"


Then I guess we shouldn't expect any mind-blowing programs from you any time soon then eh?...

When you've been programming for 35 years like I have, you'll look back and realise how daft your comments were. Lol!

TDK

Hawkblood
16
Years of Service
User Offline
Joined: 5th Dec 2009
Location:
Posted: 18th Mar 2010 17:21
@TDK
Quote: "or pass parameters to functions and then you can only get one variable back."

I haven't tried it, but I think you can make a type and pass that in a return.... ?

The fastest code is the code never written.
Brendy boy
21
Years of Service
User Offline
Joined: 17th Jul 2005
Location: Croatia
Posted: 18th Mar 2010 23:12
Quote: "I haven't tried it, but I think you can make a type and pass that in a return.... ?"

you can't return a type from a function

God is real unless declared integer.
Hawkblood
16
Years of Service
User Offline
Joined: 5th Dec 2009
Location:
Posted: 19th Mar 2010 01:04
K. That was me hoping.

The fastest code is the code never written.
Game Programer to be
16
Years of Service
User Offline
Joined: 12th Mar 2010
Location: TX
Posted: 23rd Mar 2010 14:15
Thank you,
you all have been helpful. Its working now that I used functions instead of what I did before.

------------------
Harley

Login to post a reply

Server time is: 2026-07-26 23:40:10
Your offset time is: 2026-07-26 23:40:10