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 / functions are soo cool! :)

Author
Message
David iz cool
19
Years of Service
User Offline
Joined: 21st Sep 2005
Location: somewhere lol :P
Posted: 23rd Nov 2005 17:37
u can pretty much make up your own commands if u know how with functions.im having alot of fun with them. lol
Cash Curtis II
19
Years of Service
User Offline
Joined: 8th Apr 2005
Location: Corpus Christi Texas
Posted: 23rd Nov 2005 17:48 Edited at: 23rd Nov 2005 17:50
I wouldn't use them for too much. Every variable that they contain are instance variables - they exist only in the function, and go away when the function does. Variables outside the function are not available, either. Only variables declared as constants are, and this creates a mess of variables.

I use functions for math things, like return float = getDistance3D(obj1, obj2). I never use them to change object position, variables, etc.

In my current project, I have the whole thing broken up into four files: RPG.dba, RPGsubs.dba, RPGinit.dba, and RPGfunctions.dba. This is my main loop:



This uses gosub to go and return to a chunk of code. Chunks of code are easier to identify and modify - a huge main loop can become impossible to navigate. Each sub calls functions if they need to. It lets you organize your code.

Dodo
20
Years of Service
User Offline
Joined: 8th Aug 2004
Location: eating lunch
Posted: 23rd Nov 2005 18:01
actually, if you declare the variables as global, the variables can be accessed anywhere in your code. To do this, put the global keyword before you declare your variables. For Example:



And yes, I agree, functions are very useful, and they make your code a lot tidier.

Part of solving the problem is actually noticing that the problem is there in the first place

RUCCUS
19
Years of Service
User Offline
Joined: 11th Dec 2004
Location: Canada
Posted: 23rd Nov 2005 18:04
Also if you don't want the GLOBAL command being outside of the function (since you can't put it inside from my understanding) you can dim the variables into an array and they'll be global by default. Then undimming them will allow you to... un...globalize...them

Whenever I finish projects I convert everything into tidy functions it's muce efficient in my opinion and makes everything clean.

Dodic
18
Years of Service
User Offline
Joined: 6th Nov 2005
Location: SNM (Serbia&Montenegro)
Posted: 23rd Nov 2005 21:11
yeah , sure

http://dodica.proboards75.com/index.cgi
first 20 are mods. i have 9 sofar.

Login to post a reply

Server time is: 2024-09-24 09:25:31
Your offset time is: 2024-09-24 09:25:31