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.

Dark GDK / Joystick Configurations

Author
Message
TheViking
8
Years of Service
User Offline
Joined: 16th Feb 2012
Location:
Posted: 7th Mar 2012 06:18
Hey... I had a question concerning joysticks. I was just wondering how I may go about configuring a joystick. My problem is I had 2 different joysticks, each used different fire buttons and analogue buttons. So, for instance, one would use twist for the right thumb stick, while the other would use twist for the right trigger.

So, my question is simply, how would I go about letting a player configure the joystick by pressing each button individually to detect which one was pressed so it may be saved into a data file for later use?

Hope that makes sense.
xix psycho xix
12
Years of Service
User Offline
Joined: 15th Sep 2008
Location:
Posted: 7th Mar 2012 13:13
Typically in game joystick configuration is handled by the system and you simply detect which button is being pressed or the values on an axis to implement control. I suppose you could take the same detection code and use control variables to represent the control value for, say, walking. I personally don't know of any function that returns information on what button/axis is currently being used so you will have to set up a loop and check for each control individually if you plan to use the DGDK functions. You may be able to use some DirectInput stuff to do this but that is outside of my area of knowledge, never having programmed a joystick myself. Hopefully someone can demonstrate an alternate technique for you.
TheViking
8
Years of Service
User Offline
Joined: 16th Feb 2012
Location:
Posted: 11th Mar 2012 05:30
sorry about the lengthy time since my post. But, just got my controller back, and have been trying to get it to work. I may have found a way to do it, but i'm encountering an other issue which is stopping me. So, anyways, The controller seems to only be returning a value of 0 or 1 for the analogue sticks, which I know is not correct because I use to use these commands before. Anyways, would someone be able to see why I'm getting this... I have tried returning it as a float, though it still only shows a 0 or 1.



That is pretty much how I'm just trying to determine what the value is which it returns, if I can do that then I plan to save that into an array for reference later. Any help would be GREAT because this is baffling me. Thanks
Morcilla
17
Years of Service
User Offline
Joined: 1st Dec 2002
Location: Spain
Posted: 11th Mar 2012 11:36
I think what you are looking for is

dbJoystickX();
dbJoystickY();

They return an int ranging from 0 to 1000.

TheViking
8
Years of Service
User Offline
Joined: 16th Feb 2012
Location:
Posted: 12th Mar 2012 03:38
Hey, thanks. Is there any way to call a function from an array? such as:


Or something or the sort? Thanks
xix psycho xix
12
Years of Service
User Offline
Joined: 15th Sep 2008
Location:
Posted: 12th Mar 2012 04:08 Edited at: 12th Mar 2012 04:09
If you are asking if you can check the value of a variable within an array by the result of a function call, yes you most certainly can. But the better way to do it is to store the result of the function call in a variable and then compare by the variable. Otherwise (but only if your system is REALLY slow) you may miss input if the key (or joystick) is released before the check. So something like:



If that is not what you are attempting to do, I would guess you are asking if you can call functions that are stored in an array? Sorry I just don't quite understand the question. What exactly are you trying to accomplish there?


Edit: I think i understand. Are you trying to check if the stick is being held a certain way and then print the value out? If that is what you want I will show you, otherwise just tell me what you're looking for lol.
JTK
10
Years of Service
User Offline
Joined: 10th Feb 2010
Location:
Posted: 12th Mar 2012 04:09
Function pointers:



I'm not quite sure this is the proper syntax (I don't have my compiler up to put together a demo), but I am certain it's fairly close. A simple Google search would fill in the gaps...

Regards,

JTK
TheViking
8
Years of Service
User Offline
Joined: 16th Feb 2012
Location:
Posted: 12th Mar 2012 04:23 Edited at: 12th Mar 2012 06:28
Yes, what I'm trying to do is have an array filled with the dbJoystick commands, so I may search for each one individually when getting a player to calibrate the controller. ie: Ask for them to press up on the Left thumb stick, measure the value and which function was required to get a response then store that into another array which is used only for the game to refer to which function is required. This as I mentioned is because I have noticed my XBox controller uses TwistX for the right thumbstick, while a PS3 controller will use something like Joystick Z...

Hope that clears it up... if it seems like a crappy way to do this... PLEASE let me know. Thanks.

JTK, I will try that out. I have been trying to use pointers but guess I haven't fully understood them thus far. Thanks

EDIT: JTK, that is exactly what I was looking for. However, just coming across an issue with dbJoystickFireX(n) because it requires a value for it, I am unable to use these ones. Is there anyway around this? thanks again. Now, I just need to get it to determine which is the right one for each and the max values, but, I don't think that should be too hard.
JTK
10
Years of Service
User Offline
Joined: 10th Feb 2010
Location:
Posted: 12th Mar 2012 21:43
You can store the array as void* and then typecast the value to the type you need:



Regards,

JTK
TheViking
8
Years of Service
User Offline
Joined: 16th Feb 2012
Location:
Posted: 13th Mar 2012 04:06
Sorry, I have to admit, I do not understand that one. I haven't learned much at all about typecasting. Would you be able to elaborate slightly on what that means there, or how it is used in this sense? I find it a little confusing... thanks
xix psycho xix
12
Years of Service
User Offline
Joined: 15th Sep 2008
Location:
Posted: 14th Mar 2012 14:20 Edited at: 14th Mar 2012 14:21
Ok, so the idea is that you want to store functions in arrays and then call them whenever a specific joystick button is pressed? I will try to explain first the method that I would use and then I will attempt to explain JTK's method a bit .

I would just make all of my joystick control functions have the same function prototype, something like



As you can see, each handler is given the prototype
function_name (void)

So each one can be stored in an array of function pointers and called whenever necessary. JTK's method was the same except it allows for variable types of button handlers. In his case each function pointer is stored as a pointer without a type and is converted to the appropriate type when called. That means if you have two different prototypes for button handlers you can use them both in the same array, see? But from what I read you have to return a value for each of your handlers so you could just make one prototype that returns a value, and if that value is unneeded well C++ allows us to ignore return values so you can just ignore it. If you are going to use either approach I really recommend reading a good web tutorial on function pointers, or better yet reading a c++ or even c book on the subject. Believe me function pointers deserve a book all their own! I hope this helps!


Edit: Sorry, I missed JTK's first post on the subject so I didn't mean to re-explain all of his method!
TheViking
8
Years of Service
User Offline
Joined: 16th Feb 2012
Location:
Posted: 14th Mar 2012 21:35
thanks a lot guys. I have been trying to read up on pointers and all these things myself as i prefer to know why things are done this way, though I am not a good self learner. Oh well, I think I kind of understand now, I did a little bit of both of what you said... Used TDK's advice on the majority of the buttons, but for the ones which involved a number in the brackets ie: FireX(1), I used a sort of global function to return the value and it seems to work great... thanks again guys.
xix psycho xix
12
Years of Service
User Offline
Joined: 15th Sep 2008
Location:
Posted: 15th Mar 2012 03:47
A global function? Lol you should show us what you mean I am interested to see what you came up with for that.
TheViking
8
Years of Service
User Offline
Joined: 16th Feb 2012
Location:
Posted: 15th Mar 2012 05:38
Pretty much all I mean is, when I read your code, and seen that you had a function within a function, I decided to do that for the dbJoystickFireX(n), so that the Buttons[x] array referred to a function which contained the dbJoystick functions within it. Nothing special. It just works, and was simple and didn't think of it until I read your part. Hope that makes sense. Didn't know what else to call it but a global function lol... i know its bad terminology, but meh... thanks again.
JTK
10
Years of Service
User Offline
Joined: 10th Feb 2010
Location:
Posted: 15th Mar 2012 05:41
If it works for you, then I'm glad we were able to help.

Regards,

JTK

P.S. I knew what you meant. Lol.

Login to post a reply

Server time is: 2020-09-24 22:51:25
Your offset time is: 2020-09-24 22:51:25