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 / 2 Functions?

Author
Message
Yitzu
15
Years of Service
User Offline
Joined: 14th Feb 2009
Location:
Posted: 13th Jun 2010 02:49
Can u create 2 Functions with the same name? Or can u delete one to create the other?
Brendy boy
19
Years of Service
User Offline
Joined: 17th Jul 2005
Location: Croatia
Posted: 13th Jun 2010 04:57
Quote: "Can u create 2 Functions with the same name?"

no

Quote: "Or can u delete one to create the other?"

If you mean delete function while program is running?, if yes then no.

Yitzu
15
Years of Service
User Offline
Joined: 14th Feb 2009
Location:
Posted: 13th Jun 2010 08:55
U sure, rly there isnt any way of doing any similar to this?
luskos
17
Years of Service
User Offline
Joined: 28th Jun 2007
Location:
Posted: 13th Jun 2010 10:26
Tell us what you want to do exactly and there probably is some other way to do it.I can`t imagine why you`ll ever need 2 functions with same names and why you need to delete them.I think you misunderstood what the functions are suited best and how you must use them.

Where there is a will, there is a way.
I often edit my posts, that`s who i am
Lucas Tiridath
AGK Developer
16
Years of Service
User Offline
Joined: 28th Sep 2008
Location: Kings Langley, UK
Posted: 13th Jun 2010 10:27
No, DarkBASIC Pro does not support function overloading as far as I am aware.
Yitzu
15
Years of Service
User Offline
Joined: 14th Feb 2009
Location:
Posted: 13th Jun 2010 23:00
What I want is that in one page of my code the main function i have do something, and in another page of the code do another different thing but using the same function.
Lucas Tiridath
AGK Developer
16
Years of Service
User Offline
Joined: 28th Sep 2008
Location: Kings Langley, UK
Posted: 13th Jun 2010 23:13
Well I don't quite understand what you mean by pages of code but the question I would ask is why? Can't you just create two functions with slightly different names like MyFunction1 and MyFunction2? If not, then you could always pass a boolean parameter to your function and then have an if statement which decides which action the function should take. This might look like:



Hope this helps.
Yitzu
15
Years of Service
User Offline
Joined: 14th Feb 2009
Location:
Posted: 14th Jun 2010 01:34
Yes i thought of something similar to that, well i think i might have to do it XD well, anyways ty guys
LBFN
17
Years of Service
User Offline
Joined: 7th Apr 2007
Location: USA
Posted: 14th Jun 2010 05:23
I think one of the ideas with regard to choosing to use a function is that you need to perform a repetitive task. To me, it is better to have many different functions that perform specific tasks than to try to cram many different things within a single function.

So, my advice is to split up your two functions. Doing it this way will aid you in debugging the program and will make for cleaner code, especially if you write a larger program. Lastly, it might help you if you put the game on the shelf for an extended period of time and then decide to pick it up. If your functions all accomplish one main thing, it will be easy to figure out what you were trying to do in the first place.

Good luck.
tomaszavenger
15
Years of Service
User Offline
Joined: 24th Jun 2009
Location:
Posted: 14th Jun 2010 21:43
If you want a correct function to be used, try using selection statements, and divert the program to the correct function to get around the general need for function overloading.

Login to post a reply

Server time is: 2024-09-28 18:28:38
Your offset time is: 2024-09-28 18:28:38