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 Professional Discussion / Something Interesting with Functions

Author
Message
Sasuke
18
Years of Service
User Offline
Joined: 2nd Dec 2005
Location: Milton Keynes UK
Posted: 14th Jun 2007 11:58 Edited at: 14th Jun 2007 12:01
I was reading a thread and a few people said it's good to make functions more command like.

An example:


It kind of looked nice, so I change a few more and stumbled on this:


I never knew you could do this with functions, could this be useful in any way or has anyone else used functions like this?
Cash Curtis II
19
Years of Service
User Offline
Joined: 8th Apr 2005
Location: Corpus Christi Texas
Posted: 14th Jun 2007 13:32
Nice find, I never knew that


Come see the WIP!
Ric
19
Years of Service
User Offline
Joined: 11th Jul 2004
Location: object position x
Posted: 14th Jun 2007 13:33 Edited at: 14th Jun 2007 13:35
Does that actually work? It looks to me like the comiler would read that as:



and not



If it works, then that is pretty cool - just don't see how it can, though.

Sasuke
18
Years of Service
User Offline
Joined: 2nd Dec 2005
Location: Milton Keynes UK
Posted: 14th Jun 2007 13:41
It seams to work but it has limitations. You can't use anything with brackets.
Cash Curtis II
19
Years of Service
User Offline
Joined: 8th Apr 2005
Location: Corpus Christi Texas
Posted: 14th Jun 2007 14:06
Compile this...



Come see the WIP!
Mr Kohlenstoff
17
Years of Service
User Offline
Joined: 7th Jun 2006
Location: Germany
Posted: 14th Jun 2007 14:15
Wow, great, didn't know that it works.. fantastic. Thanks!

Visit the DBPro - Speed up your game-Thread. http://forum.thegamecreators.com/?m=forum_view&t=88661&b=1
Sasuke
18
Years of Service
User Offline
Joined: 2nd Dec 2005
Location: Milton Keynes UK
Posted: 14th Jun 2007 15:00
I should give it a name, hmm... something like "Sasuke's Super Commandlike Functions" . I going to play around for awhile, see if there are more limitations and see what else I can find.

Spin Thing:
IanM
Retired Moderator
21
Years of Service
User Offline
Joined: 11th Sep 2002
Location: In my moon base
Posted: 14th Jun 2007 15:17
Well spotted - It's a nice curiosity, but it's not too useful because of the limitation of avoiding all brackets on the line. It's perfect for functions that don't need any arguments though.

Quote: "Does that actually work? It looks to me like the comiler would read that as:

+ Code Snippet

make_cube() 1,100,25,50,10"

That's what it does. You can actually type that in without using a constant an it will compile.

Xolatron
18
Years of Service
User Offline
Joined: 12th Mar 2006
Location: The Star Forge Language: DBpro
Posted: 14th Jun 2007 16:29
Hah. That's pretty neat . I'm surprised the make cube one works at all!

-Xol

Mr Kohlenstoff
17
Years of Service
User Offline
Joined: 7th Jun 2006
Location: Germany
Posted: 14th Jun 2007 17:45
A shame that you can't use any more brackets.. so it's not possible to take other functions or calculations as parameter.. :/
Does the compiler support this feature, or is it changed before by the editor? (I mean, does the editor translate 'MyCommand() x,y,z' to 'MyCommand(x,y,z)' or something?)

Visit the DBPro - Speed up your game-Thread. http://forum.thegamecreators.com/?m=forum_view&t=88661&b=1
Xolatron
18
Years of Service
User Offline
Joined: 12th Mar 2006
Location: The Star Forge Language: DBpro
Posted: 14th Jun 2007 21:24 Edited at: 14th Jun 2007 21:25
I think it would probably be the compiler. As far as I know the compiler handles everything involved in the source-code (constants, #includes, etc.). The editor doesn't do a whole lot of anything these days (since TGC can't update it).

-Xol

Mr Kohlenstoff
17
Years of Service
User Offline
Joined: 7th Jun 2006
Location: Germany
Posted: 14th Jun 2007 21:37
Oh that's interesting.. I always thought the editor would "pre-compile" it (execute all commands with '#', so #constant and #include..).

Visit the DBPro - Speed up your game-Thread. http://forum.thegamecreators.com/?m=forum_view&t=88661&b=1
Sasuke
18
Years of Service
User Offline
Joined: 2nd Dec 2005
Location: Milton Keynes UK
Posted: 15th Jun 2007 10:53
The only way I can think of getting around brackets is to do the working out before passing it to the function.

Something like this:
Humanoid
20
Years of Service
User Offline
Joined: 20th Sep 2003
Location: Finland
Posted: 15th Jun 2007 13:03



String works fine, if



hate everytime write command(something$)

Suomi Finland PERKELE!
<AMD athlon 64 3000+> <Asus A8N-E nForce4 ultra> <GF6600LE PCI-E> <1GB ram>
Hummanoid Typhoon
18
Years of Service
User Offline
Joined: 4th Aug 2005
Location: Middle of nowhere
Posted: 15th Jun 2007 14:03 Edited at: 15th Jun 2007 14:11
nice bit of info. Do i get to call this "kyuzumaki's xtra super command like functions"? lol kidding

Take a look if you miss out the first bracket and include it in your constant it works fine. As said earlier the compiler is just replacing the constants with their real values before it's compiled.



jinzai
17
Years of Service
User Offline
Joined: 19th Aug 2006
Location: USA
Posted: 16th Jun 2007 00:35
It is nice, and there are others like it, but...

I once responded to someone's question about #constant by stating it was a text substitution MACRO-like command. I always use it as a straight up assignment to a value. It can be made to do this type of thing, but...when you confuse the compiler, you are on your own.

The intent of constant seems to be text substitution, almost like define. But it is nothing like define at all. It is preprocessed, but, you cannot really use it like a define. (At least that seems like a side-effect, not a feature.)

The upshot for me is that I only use it in my code as a readability tool for bitmasks, and pi, etc.

You can't for example, rem out the remainder of the line with impunity, it can bite you very quickly.

Anyway, Sasuke...you got mad skills, just keep on doing what you are doing, and thanks.
Cheers.
TinTin
17
Years of Service
User Offline
Joined: 16th May 2006
Location: BORG Drone Ship - Being Assimilated near Roda Beta (28)
Posted: 3rd Sep 2007 14:58
I'm wondering what actualy happens...
As far as I'm aware, #constant replaces all occurencies of the named variable with the value at compile time so..

would compile as...


Nothing new or odd there, but if you assign the value to a function, won't the compiler automaticaly replace all occurencies with the function instead of just calling it, So..

would compile into...

instead of just calling the function, resulting in larger than required programs.

I haven't checked if this is correct, I'd be interested to know.

Go Create...

Cyberspace was becoming overcrowded and slummy so I decided to move. These nice chaps gave me a lift.
dark coder
21
Years of Service
User Offline
Joined: 6th Oct 2002
Location: Japan
Posted: 3rd Sep 2007 15:29
As said above #constant is just a preprocessor directive and not a data type so you can use it to shorten whatever you like.

Crit
17
Years of Service
User Offline
Joined: 24th May 2006
Location:
Posted: 3rd Sep 2007 15:36
TinTin,

That code wouldn't create inline functions - it would be translated to this before being sent to the compiler:



And for whatever reason, the compiler accepts that as valid input.
Sasuke
18
Years of Service
User Offline
Joined: 2nd Dec 2005
Location: Milton Keynes UK
Posted: 14th Sep 2007 12:26 Edited at: 14th Sep 2007 12:27
Another function thing.

When I was playing around with function I noticed you could put a point between the the words like:

My.CoolFunction( <something> )

And the compiler excepts this, but why won't it except it if the function returns something:

a = My.CoolFunction( <something> )

It will only read up to the point, whats up with that?
Sasuke
18
Years of Service
User Offline
Joined: 2nd Dec 2005
Location: Milton Keynes UK
Posted: 14th Sep 2007 13:20 Edited at: 14th Sep 2007 13:20
I see, thanks for that WindowsKiller
Lucy
17
Years of Service
User Offline
Joined: 19th Apr 2007
Location: Roanoke, VA USA
Posted: 14th Sep 2007 18:47
Definitely a good find.

Nothing I say is intended to be rude. My autism means that I do not know what is rude and what isn't rude. I apologize if I seem rude. It is not my intention.

Login to post a reply

Server time is: 2024-04-24 18:50:07
Your offset time is: 2024-04-24 18:50:07