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 / Functions as complete apps

Author
Message
Latch
17
Years of Service
User Offline
Joined: 23rd Jul 2006
Location:
Posted: 13th Nov 2009 19:28
Many may be aware that subroutines can be written inside of functions and be local to that function. If you didn't know, well, now you know. I had done this but I hadn't really taken advantage of it much until recently. The usefulness of this is far reaching as I see it.

It is possible to create an entire working application all contained in a single function. You can then #INCLUDE this function or plop it directly in the source of another application. To me, this means having a plugin system.

For example, let's say you have a matrix editor. You've got it working great to create, modify, texture, etc. any matrix you want. But you started thinking, it would be great to expand this into a full level editor. Instead of trying to rework the code in your matrix editor, you could create a function with it's own set of local variables and subroutines that runs completely in and by itself that manages objects. Once the function is done, you call it from the main code of the matrix editor, and your object manager will do it's thing. When you are done, you can release control back to the matrix editor.

This usage may seem obvious, but until you create an entire working application that's contained in a function, you may not realize how useful it can be. The thing is to, the variables are local to the function. You don't have to work on the main app and the plugin at the same time to make sure they work together if you don't want to. And, if you use local arrays as the variables in your function, you can undim all of them so there's no memory overhead when you exit the function.

The use of local subroutines is really what makes this nice. You can use local variables with the local subroutines as if they were functions themselves. It takes a little getting used to and uses a slightly different method than passing values as parameters to standard functions. You can of course use other functions within functions, you just can't write them as included inside a parent function - that's why I like the use of subroutines. A single function can be used for an entire application.

So instead of thinking of functions as just value calculators, or bits of code to perform a task or save a file, think of them as potential complete applications that can be shared and run concurrently in one common source.

Enjoy your day.
Libervurto
17
Years of Service
User Offline
Joined: 30th Jun 2006
Location: On Toast
Posted: 13th Nov 2009 21:15
I think this is the first musing thread we've had
This could prove very useful, especially for team projects.

"With games, we create these elaborate worlds in our minds, and the computer is there to do the bookkeeping." - Will Wright
demons breath
20
Years of Service
User Offline
Joined: 4th Oct 2003
Location: Surrey, UK
Posted: 14th Nov 2009 00:27
That sounds really interesting - would this mean it would also work across languages? Or would you have to stick with the same language.

"The fools may crash down upon us in thunderous waves, but we shall Jeku slap them back from whence they came"
-BiggAdd Oct 28th 2009
Latch
17
Years of Service
User Offline
Joined: 23rd Jul 2006
Location:
Posted: 14th Nov 2009 05:10
Quote: "That sounds really interesting - would this mean it would also work across languages?"

I'm speaking specifically of DBC. I don't know if DBPro function variables are static. DBC function variables are; they will hold the same value even if you exit the function.

For lnaguages like C, you have the ability to use things like DLLs that can be completely self contained applications if you will.

For DBC, this could be a "plugin" system for source code. This wouldn't work after the source is compiled into an exe.

Enjoy your day.
Caleb1994
15
Years of Service
User Offline
Joined: 10th Oct 2008
Location: The Internet you idiot!
Posted: 15th Nov 2009 22:40
That is kinda how c++ works, your program is contained in one function and ran from there like main() or WinMain() or DarkGDK() depending on the type of program(like WinMain() is used when handling windows stuff, and DarkGDK() is used for, well, dark GDK stuff)

New Site! Check it out \/
Kevin Picone
21
Years of Service
User Offline
Joined: 27th Aug 2002
Location: Australia
Posted: 5th Dec 2009 14:08
Quote: "I don't know if DBPro function variables are static."


Nah, this is one of those DBC to Dbpro gotchas.

Login to post a reply

Server time is: 2024-04-26 23:35:17
Your offset time is: 2024-04-26 23:35:17