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 / Need refresh on FUNCTION capabilities in DBpro

Author
Message
zenassem
21
Years of Service
User Offline
Joined: 10th Mar 2003
Location: Long Island, NY
Posted: 17th Apr 2007 09:51
Can I code a single function that can handle 1 to MAX number of parameters?
(!)- Without forcing the user of the function to pass in values for MAX parameters.


If an example of what I am asking helps:

Say I want a function "f_ChKeyPress" to take in a varying # of scancodes as paramaters (# from 1 - MAX), and return a boolean result.

function f_ChKeyPress(par1, par2, par3... MAX)
blah,blah
endfunction result

I want the user of the function to be able to provide 1 - Max # of parameters without having to provide (NULL) values for un-needed parameters.

So to check for 1 key being pressed...

KPresult=f_ChKeyPress(203)

To check for 2 keys being pressed...

KPresult=f_ChKeyPress(203,200)

Is it possible to do this in DBpro? How would you Declare the Function?
Milkman
18
Years of Service
User Offline
Joined: 30th Nov 2005
Location: United States
Posted: 17th Apr 2007 10:13 Edited at: 17th Apr 2007 10:14
Unfortunately, you can't natively.

What you can do, however, is use ianm's function pointer dll to do this, although it's a bit of a hassle for just a normal function call. You would have to define two functions for every one, and pass in an extra parameter (the number of parameters to be used) every time.



Who needs a signature?
zenassem
21
Years of Service
User Offline
Joined: 10th Mar 2003
Location: Long Island, NY
Posted: 17th Apr 2007 10:18
Thanks again Milkman!

Not exactly the answer I was hoping for. I'll have to work around it.
wildbill
18
Years of Service
User Offline
Joined: 14th Apr 2006
Location:
Posted: 17th Apr 2007 19:13
Just some thought, don't know if this will work.
You could try storing the scancodes in a expanding array and as each key is pressed add it to the stack. Since arrays are global you just have a function manipulate the array data for use.

keypress = scancode()
KeyValues(keypress)
function KeyValues(keypress)
add to stack KeyCheck()
KeyCheck() = keypress
endfunction keypress$

You would have to play around with multiple keys. But it should work.
zenassem
21
Years of Service
User Offline
Joined: 10th Mar 2003
Location: Long Island, NY
Posted: 17th Apr 2007 20:29
Wildbill, thanks for the help.

My problem isn't in recording or retrieving the keystates. I can and am nearly complete in doing so for every key on the keyboard, including if a/many key(s) are held, for how long, are they released, parsing buffers for combos for fighting games etc...

My problem is providing the ENDUSER (being another programmer or myself) with easy functions to my data elements without them having to know all the details about how or why the data is stored, from inside there code.

So my data is sorta like a library. With easy function calls to get, compare, and set keyboard states.

If it works well, than I'd like to recode it as a DLL. Right now I'm just testing my idea by coding the Keyboard Input Handler in DB.
IanM
Retired Moderator
22
Years of Service
User Offline
Joined: 11th Sep 2002
Location: In my moon base
Posted: 17th Apr 2007 21:08
You can build an argument stack using an array - it limits you a little, and clutters your code, but it works:



It would be fairly simple to change the argument stack to hold a UDT for any type, and add a function to get the type.

Bear in mind also, that you are limited to 9 arguments for a DLL command too.

zenassem
21
Years of Service
User Offline
Joined: 10th Mar 2003
Location: Long Island, NY
Posted: 17th Apr 2007 21:45
Very nice IanM. Thankyou! I Wasn't able to see things that way.

Now It's got me thinking... I'll see what I can do with it.
Cave Man
18
Years of Service
User Offline
Joined: 22nd Aug 2006
Location: North Carolina, US
Posted: 18th Apr 2007 02:38
Or you could pass a string to the function and parse the numbers out using "mid$".

A string like "57/34/233" using the "/" as a separator and using "val" to change it from a string to a number.
Milkman
18
Years of Service
User Offline
Joined: 30th Nov 2005
Location: United States
Posted: 18th Apr 2007 04:27
Not to mention that that method is extremely slow and inefficient.

Who needs a signature?
zenassem
21
Years of Service
User Offline
Joined: 10th Mar 2003
Location: Long Island, NY
Posted: 18th Apr 2007 23:07 Edited at: 18th Apr 2007 23:12
I'm a moron!!!!

Well I stepped away from it for a night. And today things were a bit clearer. I was truly over-thinking what I wanted to do.

I am basically coding functions for other programmers and/or myself to utilize my Keyboard Input Data in a clean and efficient way rather than having to know about, or touching the storage types themselves. Almost like Private data and Public functions in C++.

My routine records info about every key, every loop. One piece of info is whether a key is being pressed.
So I wanted to provide a function for users to retrieve this.

All good so far.


Then I also wanted them to be able to compare whether two or more keys are being pressed...

This is where my thinking went wrong. I really don't need to provide a function or multiple functions for that. Since the single key function returns a boolean value of whether or not a single key is being pressed, and my routine already records all other keystates. I should leave it up to the programmer to use boolean operators for multiple keychecks.

so in their code they would do the following



LOL! Does stuff like this happen to anyone else????
IanM
Retired Moderator
22
Years of Service
User Offline
Joined: 11th Sep 2002
Location: In my moon base
Posted: 21st Apr 2007 01:32
Of course not. I'm far too smart for that

Login to post a reply

Server time is: 2024-11-25 19:39:49
Your offset time is: 2024-11-25 19:39:49