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.

DarkBASIC Discussion / [DBC] Subroutine to function - WHY IS MY PREVIOUS POSTING LOCKED?

Author
Message
The Wizard of Aus
17
Years of Service
User Offline
Joined: 14th Sep 2007
Location: The Land Down Under, AUSTRALIA
Posted: 25th Sep 2007 07:15
Why is my previous posting on this subject locked?

The Wizard

The simplest way to learn speed reading is to get an unexpected letter from the taxation office
Zombie 20
18
Years of Service
User Offline
Joined: 26th Nov 2006
Location: Etters, PA
Posted: 25th Sep 2007 11:48 Edited at: 25th Sep 2007 11:54
Hi wiz,

I'm assuming that you're new to the fourums and all that jazz. Look have you posted about the same question or just a small variation of your problem, mods don't need that in the threads and so they get locked, so what seems to be the issue?

Okay saw your thread, dude come on you cannot be serious. TDK's tuts are top-notch, I do not see why you have an issue here, not to mention that what you're trying to do is nowhere near a subroutine.

This is a subroutine



your thread was locked because it made no sense whatsoever. Now look, you may think I'm being mean but I'm just very tired having come off of work so please bare with me, I have to recaffinate but dude come on..here's what you could do with that code.




I hope this has answered your question as to what a subroutine is and as far as its uses, boundless though some older members would yell at me and say use functions like a good boy but I'm just stubborn.

Libervurto
18
Years of Service
User Offline
Joined: 30th Jun 2006
Location: On Toast
Posted: 25th Sep 2007 22:47
@Zombie


Your indenting is strange for your subroutines; the label and RETURN are just like any other multi-line command/loop.
Also, sorry for being picky but your example would return to just after the gosub call and bump into the subroutine, running it a second time.
Here's the changes:

Now it will only run the Test_1 routine once and then end
This is a better example of how to use gosubs as now we have a routine that is "outside" the main program.

In programming, nothing exists
The Wizard of Aus
17
Years of Service
User Offline
Joined: 14th Sep 2007
Location: The Land Down Under, AUSTRALIA
Posted: 26th Sep 2007 07:27
Zombie 20

OK! I said

Quote: "I currently use this as a subroutine. How can I change it to use as a function and how would I call it?"


What I should have said was

Quote: "I currently use this in a subroutine. How can I change to use in a function and how would I call it?"


Check

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

and you’ll see what I ended up with.


The Wizard

The simplest way to learn speed reading is to get an unexpected letter from the taxation office
Zombie 20
18
Years of Service
User Offline
Joined: 26th Nov 2006
Location: Etters, PA
Posted: 26th Sep 2007 11:49


I know my coding style sucks haha, and thank you for fixing that obese, acutally just got off of work so I'll be doing some coding here in a few.

TDK
Retired Moderator
22
Years of Service
User Offline
Joined: 19th Nov 2002
Location: UK
Posted: 27th Sep 2007 03:01
Basically you double-posted:

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

This happens frequently with new users as they post and when their thread doesn't immediately appear (due to the approval process), they post it again but with a slightly different topic line.

As they were both on the same subject, I locked the one which no-one had replied in.

TDK_Man

Zombie 20
18
Years of Service
User Offline
Joined: 26th Nov 2006
Location: Etters, PA
Posted: 27th Sep 2007 13:32
well mr. wizard as far as I know you cannot use a subroute in a function and why the hell would you want to anyway? Both are similar but I don't really see an application that would need it, I mean functions are very very useful, I'm just very very lazy.

TDK
Retired Moderator
22
Years of Service
User Offline
Joined: 19th Nov 2002
Location: UK
Posted: 27th Sep 2007 18:53
I forgot to add...

Sometimes, procedures are better than functions - life is often much easier when you don't have to worry about variable scope (local variables).

To be honest, I rarely use functions. They do have their uses occasionally though, so I'm not saying I never use them...

Procedures which use lots of global variables are often better left as procedures in DB Classic because unlike DBPro, you can't declare native global variables.

TDK_Man

Insert Name Here
18
Years of Service
User Offline
Joined: 20th Mar 2007
Location: Worcester, England
Posted: 27th Sep 2007 18:54
Quote: "To be honest, I rarely use functions. They do have their uses occasionally though, so I'm not saying I never use them..."

We have something in common!

Our home is our world, our life, home is our world...
Homeworld: The ladder
Libervurto
18
Years of Service
User Offline
Joined: 30th Jun 2006
Location: On Toast
Posted: 27th Sep 2007 19:18
Quote: "Procedures which use lots of global variables are often better left as procedures in DB Classic because unlike DBPro, you can't declare native global variables."

I think TDK means procedures that alter lots globals; because you can only return one variable from a function it's hard to make the same procedure as a function.

In programming, nothing exists
The Wizard of Aus
17
Years of Service
User Offline
Joined: 14th Sep 2007
Location: The Land Down Under, AUSTRALIA
Posted: 28th Sep 2007 09:03
How can I explain?

Let’s start at the beginning.

This is from TDK_Man's tutorials on how to get a sub-string from a string



and I said

Quote: "I currently use this in a subroutine."


Here’s how I used it in a subroutine



Then I said

Quote: "How can I change to use in a function and how would I call it?"


Again, if you check

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

you’ll see how I changed to use in a function.



The Wizard

The simplest way to learn speed reading is to get an unexpected letter from the taxation office
The Wizard of Aus
17
Years of Service
User Offline
Joined: 14th Sep 2007
Location: The Land Down Under, AUSTRALIA
Posted: 1st Oct 2007 04:29
Does that explain more clearly?


The Wizard

The simplest way to learn speed reading is to get an unexpected letter from the taxation office
gearce
18
Years of Service
User Offline
Joined: 18th Dec 2006
Location: ex SCOTLAND, now MELBOURNE, Australia
Posted: 3rd Oct 2007 12:31 Edited at: 4th Oct 2007 04:25
Hi there Wizard.

Quote: "Here’s how I used it in a subroutine."


Here's another way you could have used it in a subroutine. Same programme some lines shorter simply by removing two repetitive lines and putting them in the subroutine.




gearce
(GRC)

LANG MEY YER LUM REEK
That's ODD ...... In 1911, 3 men were hung for the murder of Sir Edmund Berry at Greenbury Hill, their last names were Green, Berry, and Hill.
The Wizard of Aus
17
Years of Service
User Offline
Joined: 14th Sep 2007
Location: The Land Down Under, AUSTRALIA
Posted: 4th Oct 2007 06:23
Thanks gearce. Much appreciated.

The Wizard

The simplest way to learn speed reading is to get an unexpected letter from the taxation office
gearce
18
Years of Service
User Offline
Joined: 18th Dec 2006
Location: ex SCOTLAND, now MELBOURNE, Australia
Posted: 9th Oct 2007 07:37
Re all comments about returning variables from a function. Functions do not necessarily have to return a variable.

gearce
(GRC)

LANG MEY YER LUM REEK
That's ODD ...... In 1911, 3 men were hung for the murder of Sir Edmund Berry at Greenbury Hill, their last names were Green, Berry, and Hill.

Login to post a reply

Server time is: 2025-05-31 21:14:35
Your offset time is: 2025-05-31 21:14:35