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 / Goto gosub(need help......)

Author
Message
Pyro gamesta
19
Years of Service
User Offline
Joined: 28th Apr 2005
Location:
Posted: 11th Dec 2005 06:32
Im am a dark basic user and I am really excited to say that I am making progress!!!

But what is getting to me is to me is the goto commands....
I have heard about these, and many times people pefer gosub over goto.

can you guys help me out with my code please?

<code>

Rem Main Menu:


Rem (optional if you want your program windowed)
set window on




Print "Version:"

set text size 20
center text 320,20, "Title Here"

Rem Text Links


text 1,300, "New Game"
text 1,320, "Load Game"
text 1,340, "Options"
text 1,360, "Check For Updates"
text 1,380, "Exit"






set text size 12
text 1,450, "Made By (Team or Author)"
</code>


can i also get some direction on making text button please guys??

thank you

When there is a will.....theres a way!!!
SimSmall
20
Years of Service
User Offline
Joined: 7th Aug 2004
Location: United Kingdom
Posted: 11th Dec 2005 19:43 Edited at: 13th Dec 2005 19:38
I think for button, you're after something like:



Before it works you'll have to define labels (set in the MenuTarget array) - buttons can be made using the box command, and setting the co-ordinates to match button_co-ords. using the ink command before drawing the boxes will change the colour of the box, after drawing boxes, change the colour again AFTER drawing the boxes, otherwise the text will be the same colour, and so invisible (but draw boxes BEFORE the text commands, otherwise it will appear over the text, and no-one will know which button means what because it will again be invisible...)

If you're not sure what I've done here, I'm sure others will explain it (or even produce something easier and more useful)

as for gosub and goto - use goto if you never intend to return to that point, if you EVER want to return, then gosub always.

...maybe one day I'll finish a project
Pyro gamesta
19
Years of Service
User Offline
Joined: 28th Apr 2005
Location:
Posted: 11th Dec 2005 22:47
ill try this....
it does look tricky tho
lol

bbl

When there is a will.....theres a way!!!
Pyro gamesta
19
Years of Service
User Offline
Joined: 28th Apr 2005
Location:
Posted: 11th Dec 2005 22:52 Edited at: 11th Dec 2005 22:53
hmmm there are errors in that code you gave me that dont allow me to run the program...

is there an easier way to do this in my code??

if so how here it is again.



Thank you

When there is a will.....theres a way!!!
Antidote
19
Years of Service
User Offline
Joined: 18th Mar 2005
Location: San Francisco, CA
Posted: 11th Dec 2005 23:29 Edited at: 11th Dec 2005 23:30



Let me know how that works out.



TDK
Retired Moderator
21
Years of Service
User Offline
Joined: 19th Nov 2002
Location: UK
Posted: 12th Dec 2005 00:46
As you can see from Antidote's code, there are always alternatives to using Goto and you should use them.

The basic problem is that Goto is a conditional (or unconditional) jump to another part of your program which has no structured return. You are responsible for the return with another Goto.

If you don't, then the code soon becomes a tangled mess and all the jumping about makes it very difficult for you to follow - never mind anyone else when you get stuck!

Gosubs (and functions too) both have built-in 'returns' so you know that once the call has been made, the program control always comes back and continues from the very next line. You don't have to worry about it.

So if anyone still uses Goto, then there's no excuse - switch to Gosubs or functions before it's too late!

TDK_Man

Pyro gamesta
19
Years of Service
User Offline
Joined: 28th Apr 2005
Location:
Posted: 12th Dec 2005 01:02
TDK man you are the best!!! When im stuck im always looking for awesome peoples like you to cheer me up

Antidote when i place the code in dark basic and try to run it, there are know errors....but the screen is just blank

When there is a will.....theres a way!!!
Antidote
19
Years of Service
User Offline
Joined: 18th Mar 2005
Location: San Francisco, CA
Posted: 12th Dec 2005 01:09 Edited at: 12th Dec 2005 01:10
woops sorry that's my mistake, let me fix that. *Copies code over, and fixes* here you go.





Pyro gamesta
19
Years of Service
User Offline
Joined: 28th Apr 2005
Location:
Posted: 12th Dec 2005 02:20 Edited at: 12th Dec 2005 02:36
got it to work!!!

thx all i be back if im stuck again

When there is a will.....theres a way!!!
SimSmall
20
Years of Service
User Offline
Joined: 7th Aug 2004
Location: United Kingdom
Posted: 12th Dec 2005 17:42
[quote]So if anyone still uses Goto, then there's no excuse - switch to Gosubs or functions before it's too late![quote]

I will use goto when setting display modes and other things like that (before the user can have any control) - since you will NEVER return there I see no problemo with the goto... setting options in an options screen however, definately not goto since you would return to the main menu...

Other than that - listen to TDK_man (and everyone else come to think of it )

...maybe one day I'll finish a project
TDK
Retired Moderator
21
Years of Service
User Offline
Joined: 19th Nov 2002
Location: UK
Posted: 12th Dec 2005 18:59
Quote: "I will use goto when setting display modes and other things like that (before the user can have any control) - since you will NEVER return there I see no problemo with the goto"


To be honest, if anyone really, really wants to use Goto, then there's nothing I or anyone else can say or do to stop them.

My point is that it's old fashioned, has been left in DB for backward compatibility for BASIC programmers who haven't done any programming since the 1970's (when Procs and Functions didn't exist) and has no real use in a modern language like DB.

Yes you can use Goto if you know what you are doing - and I appreciate that you do - but if a newcomer doesn't, then Goto makes it far, far too easy to write messy code. If someone is new to programming, then they should be actively discouraged from using it.

Anyone who thinks that there is no way to avoid goto in some programs should just ask on here because such a program doesn't exist.

But what you say interests me...

If you use Goto to a section which sets the display mode, where is that section? It can't be at the end as without another Goto to get back to the start, you would never get to your main code.

If it's at the start, then why would you need a Goto?

Personally, I can't see how it could be any simpler to have a:

Setup:
Return

block at the end of the program which sets up all the screen and program options and use Gosub Setup on the first line of the program.

At the end of the day, it comes down to personal choice.

To be honest, if I see code in a post from a newcomer using Goto's, I will think twice about trying to help - especially if it's more than a few lines long, because it can be so difficult to follow.

TDK_Man

Grog Grueslayer
Valued Member
19
Years of Service
User Offline
Joined: 30th May 2005
Playing: Green Hell
Posted: 12th Dec 2005 21:46
Quote: "To be honest, if I see code in a post from a newcomer using Goto's, I will think twice about trying to help - especially if it's more than a few lines long, because it can be so difficult to follow."


I'm with you man. It's better to just teach the person to use gosub instead and let them change the code to gosubs rather than us doing it for them.

Really TGC need to edit the description in the help files for goto... add that it's best to use gosub or functions rather than goto because of it's inability to return by itself.


SimSmall
20
Years of Service
User Offline
Joined: 7th Aug 2004
Location: United Kingdom
Posted: 12th Dec 2005 23:55
Quote: "Personally, I can't see how it could be any simpler to have a:

Setup:
Return"

My way is:

(doing all the setup stuff)
blah blah
get some CL$()'s if it's blank, go right past it
otherwise take the relevant actions with a lot of complicated ifs

Finished setup:
Now everything's setup, essentially treat this as the new line 1
Quote: "goto because of it's inability to return by itself"

I don't want it to go above this line now, so I don't want an auto-returning construct. Could be done with a function, but I like the good ol' way...

People new to programming, DON'T COPY ME! it's very common for me to do things my own way... Very inefficient, and boo'd and hissed at all round...

...and with this, I assume the Pro-Noob AntiBoob (and any other similar) justice won't like me now...

...maybe one day I'll finish a project
Grog Grueslayer
Valued Member
19
Years of Service
User Offline
Joined: 30th May 2005
Playing: Green Hell
Posted: 13th Dec 2005 00:39
Quote: "...and with this, I assume the Pro-Noob AntiBoob (and any other similar) justice won't like me now..."


Using "goto" isn't on my list of "boob" things so you're still cool to me. That signature is linked to my profile that explains all about the PNABJL.

If I really wanted to be picky I would add people that don't indent their code... but that's going to far.


Dodic
18
Years of Service
User Offline
Joined: 6th Nov 2005
Location: SNM (Serbia&amp;Montenegro)
Posted: 13th Dec 2005 00:47
hm....

i make free 3d models , then you tell me some stuff about usseles posts and then something heppen...
Pyro gamesta
19
Years of Service
User Offline
Joined: 28th Apr 2005
Location:
Posted: 13th Dec 2005 04:52 Edited at: 14th Dec 2005 03:49
I was stuck at coding these.....i dont understand!!!(still am....) it would have takin me ages just to do this command??

i wanna learn how to code these darn things myself lol...
without them i cant go anywhere in my on programs!!!

was it heard for you guys at first

or did you guys have to turn for help also

When there is a will.....theres a way!!!
TDK
Retired Moderator
21
Years of Service
User Offline
Joined: 19th Nov 2002
Location: UK
Posted: 13th Dec 2005 06:44
Quote: "Very inefficient, and boo'd and hissed at all round..."


Well I for one wouldn't boo and hiss at you.

You know what you are doing and I wouldn't dream of trying to convert you with your tried and trusted methods. My comments are aimed only at newcomers to programming - not people with years of programming experience like yourself.

Using Goto's is a bad habit to get into if you've just started programming.

Quote: "was it hard for you guys at first"


Well I'm just about getting the hang of it. It's taken me about 25 years so far though!

TDK_Man

Grog Grueslayer
Valued Member
19
Years of Service
User Offline
Joined: 30th May 2005
Playing: Green Hell
Posted: 13th Dec 2005 10:56 Edited at: 13th Dec 2005 11:03
Quote: "was it heard for you guys at first

or did you guys have to turn for help also
"


When I learned Basic there was no internet... Modems didn't even exist yet, neither did 3 1/2 disks. I got some help from my Dad but I pretty much had to learn most by myself by looking at some books we had that contained programs I could type into the computer.

Here's what I learned on:


A Texas Instruments Professional computer.

Speed: 5mhz
Memory: 64k
Storage: 2 360k 5 1/4 drives
Max Colors: 8
No Harddrive

Very hard to learn but oh so fun.


SimSmall
20
Years of Service
User Offline
Joined: 7th Aug 2004
Location: United Kingdom
Posted: 13th Dec 2005 19:40
I've just seen my own mistake (only now!) my code snippet in the last few lines said goto - that should not have been a goto as unless I chose exit, I would return to the menu later on...

...maybe one day I'll finish a project
Pyro gamesta
19
Years of Service
User Offline
Joined: 28th Apr 2005
Location:
Posted: 14th Dec 2005 03:45 Edited at: 14th Dec 2005 03:47
lol wow guys i love dark basic

the only thing in my way is school and hmw lol!!!!

wow TDK_man

wow Grog Grueslayer

When there is a will.....theres a way!!!
Pyro gamesta
19
Years of Service
User Offline
Joined: 28th Apr 2005
Location:
Posted: 14th Dec 2005 04:11


I have manged to do this guys!!! with your help!!

but how do i go back with a specific Key?

(check out the check updates section)

When there is a will.....theres a way!!!
TDK
Retired Moderator
21
Years of Service
User Offline
Joined: 19th Nov 2002
Location: UK
Posted: 14th Dec 2005 06:51
When you jump to a procedure where you need to wait before returning, don't use a Do..Loop, use a Repeat..Until.

A bit like this:



That way you can say repeat until a condition is met - which can be one of the available keys has been pressed. You then exit the procedure and return back to where you Gosub'ed from.

I just made up the Scancode numbers in the above example. You use a similar method if you create buttons. For example, click on the 'Play Game' button and you might use PlayGame=1.

Your Repeat loop would be 'Until PlayGame=1'.

TDK_Man

Login to post a reply

Server time is: 2024-09-24 11:22:53
Your offset time is: 2024-09-24 11:22:53