Castle Paradox Forum Index Castle Paradox

 
 FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 
 Gamelist   Review List   Song List   All Journals   Site Stats   Search Gamelist   IRC Chat Room

(Advanced) fixing On-keypress trigger for joystick control

 
Post new topic   Reply to topic    Castle Paradox Forum Index -> HELP!
View previous topic :: View next topic  
Author Message
athenshorseparty




Joined: 07 Dec 2013
Posts: 5

PostPosted: Sat Dec 07, 2013 10:49 pm    Post subject: (Advanced) fixing On-keypress trigger for joystick control Reply with quote

Hi all. Nice forum. I first heard about and messed around with this software back in high school (class of 07) but I'm really glad it's still continuously being updated!

I am working on a game and would like to implement full use of the USB joystick to replicate the 8 bit experience as much as possible, but I've noticed a bug (or feature?) in the implementation of the "on-keypress script" trigger for maps:

Joystick buttons 1-16 activate the trigger just fine, but sadly the D-pad buttons don't. (The calibration screen works fine so I don't think it's a backend compatibility issue). Does anyone know a simple way to fix this? I looked at plotscript.hsd but it only defines the functions and constants.

Is this something you'd have to patch the source-code to fix? How difficult do you think it would be? I have a lot of experience with some higher level scripting languages (javascript, PHP) but haven't ever done anything really extensive in BASIC. Still it seems like if the other joystick buttons can trigger the script there should be a simple fix to get it to include the 4 joystick axis constants.

There may be some kind of simple work-around that I'm missing here using the other script triggers but I can't figure it out right now.

Either way, thanks for an awesome utility with such a capable scripting language. It's a dream come true.

EDIT:
sourcecode just in case:
plotscript, waitforkeys, begin
if (key is pressed(key:J),and,jumping==0) then, begin
jumping:=1
jump
end

if (key is pressed(key:G),and,attacking==0) then, begin
attacking:=1
suspend player
attack
end


if (key is pressed(joy:y down)) then, begin
show textbox (1) #only works if another key is being pressed
end


if (key is pressed(joy:button1)) then, begin
show textbox (1) #works just fine
end

end
Back to top
View user's profile Send private message
athenshorseparty




Joined: 07 Dec 2013
Posts: 5

PostPosted: Sat Dec 07, 2013 10:58 pm    Post subject: Reply with quote

Whoa duh. I put a while loop in the autorun script and it works fine now.

Now I simply need to figure out how to map the controls!
Back to top
View user's profile Send private message
athenshorseparty




Joined: 07 Dec 2013
Posts: 5

PostPosted: Sun Dec 08, 2013 5:33 am    Post subject: Reply with quote

Upon further tooling around I've figured out that it's not just the D-pad control on the joystick that doesn't trigger it. It's every joystick button other than button 1, at least with my particular game controller (Logitech Precision - 10 button)
Back to top
View user's profile Send private message
TMC
On the Verge of Insanity




Joined: 05 Apr 2003
Posts: 3240
Location: Matakana

PostPosted: Sun Dec 08, 2013 8:11 am    Post subject: Reply with quote

Hi. I don't have a joystick, so I can't test any of this stuff. Hopefully James can.

I looked at the code for the onkeypress script and it definitely looks like joystick movement (of the main axis) should cause the onkeypress script to trigger, so I'm surprised that it doesn't. (Note that secondary axes are unsupported, but your controller only seems to have one anyway.) But I did notice that certain other places where the engine waits for a keypress ignore joystick movement. (I don't really want to touch that because I don't understand how the joystick calibration stuff works.)

Also it definitely looks like all of the first 16 buttons on the joystick (not counting secondary d-pads/axes) should trigger the onkeypress script.

Unfortunately we don't yet have a testing game which reports all the joystick input, as we do for keyboard input. But maybe I could get you to test whether "key is pressed(joy:button2)" for button 2 and higher buttons works?
_________________
"It is so great it is insanely great."
Back to top
View user's profile Send private message Send e-mail
athenshorseparty




Joined: 07 Dec 2013
Posts: 5

PostPosted: Sun Dec 08, 2013 9:00 am    Post subject: Reply with quote

Okey doke. I'm running the latest stable build listed on the wiki (Beelzebufo) by the way (Windows XP sp3 if that makes any difference.

As I've been messing around with stuff since last night, it seems like all the joystick inputs are getting detected just fine by the "key is pressed" function within the scripts themselves. I switched to running a while loop on one of the autoload triggers and I've been able to make some workable controls after a little experimentation, it does seem like it'd be a lot easier to control/predict for the flow and processing order. I'd prefer to just have a control function on the keypress trigger and save the autoloads for more specific scripts.

Anyway, I made another .hss to test the "on-keypress" trigger. My Logitech Precision game pad has only 10 buttons (and a 4 button D-pad) and here's what happened...

Code:

plotscript, waitforkeys, begin

  if (key is pressed(joy:button 1)) then, begin
  show text box (1)
  end

  if (key is pressed(joy:button 2)) then, begin
  show text box (2)
  end

  if (key is pressed(joy:button 3)) then, begin
  show text box (3)
  end

  if (key is pressed(joy:button 4)) then, begin
  show text box (4)
  end

  if (key is pressed(joy:button 5)) then, begin
  show text box (5)
  end

  if (key is pressed(joy:button 6)) then, begin
  show text box (6)
  end

  if (key is pressed(joy:button 7)) then, begin
  show text box (7)
  end

  if (key is pressed(joy:button 7)) then, begin
  show text box (7)
  end

  if (key is pressed(joy:button 8)) then, begin
  show text box (8)
  end

  if (key is pressed(joy:button 9)) then, begin
  show text box (9)
  end

  if (key is pressed(joy:button 10)) then, begin
  show text box (10)
  end

  if (key is pressed(joy:y down)) then, begin
  show text box (11)
  end

  if (key is pressed(joy:y up)) then, begin
  show text box (12)
  end

  if (key is pressed(joy:x right)) then, begin
  show text box (13)
  end

  if (key is pressed(joy:x left)) then, begin
  show text box (14)
  end

end


I was wrong about before: All of the inputs load the script correctly except for input 2 and input 10 and the 4 directional inputs. If I hold a key on the keyboard down I can the textbox to come up for all of them but for some reason 2 and 10 and the d-pad won't call the script on their own which is weird since buttons 1 and 3-9 call the script fine.

Another thing I notice but don't know if there's any significance to is that the text box itself comes up when the button is held down but the text doesn't load til its released. Interesting.

(Also, it's worth pointing out that when I alt+tab to minimize game.exe and type here, then go back to the executable all of the joystick input stops working even though the keys still do.)

AND for good measure, just to see whether any of the weirdness is coming from my specific game pad I changed the function to work with a while loop on the autoload trigger. The inputs all work fine in that case.

I only have this one USB controller to mess around with though if anybody wants to download that script all you have to do is compile it and put it in the on-keypress trigger of your first map to test it out. (and fill out corresponding text-boxes so you know what's what). It'd be cool if somebody else would try some different controller/OS configurations. It doesn't seem like a lot of games being made on this engine are really bothering too much with the joystick functionality which is a shame, because I love being able to play games with a controller.

thanks for the feedback![/code]
Back to top
View user's profile Send private message
TMC
On the Verge of Insanity




Joined: 05 Apr 2003
Posts: 3240
Location: Matakana

PostPosted: Sun Dec 08, 2013 9:50 pm    Post subject: Reply with quote

Thanks for the testing. Buttons 2 and 10 do work but don't trigger the onkeypress script? I had another thorough look at the code for that, and can see absolutely no explanation. Argh!

Quote:
Another thing I notice but don't know if there's any significance to is that the text box itself comes up when the button is held down but the text doesn't load til its released. Interesting.


That's because when you hold down a key the script is run every tick and runs "show textbox". Which causes the textbox to start displaying again from the beginning. On the first tick none of the text has "faded" in yet.

Quote:
(Also, it's worth pointing out that when I alt+tab to minimize game.exe and type here, then go back to the executable all of the joystick input stops working even though the keys still do.)

Yikes! Does this fix itself after you press a key or do other things like switch away and back to the window again? Or do you have to quit and restart the game?

And yeah hardly anyone considers joysticks and unfortunately our joystick support is supposedly bad in places (there are apparently a couple of things which require the keyboard)
_________________
"It is so great it is insanely great."
Back to top
View user's profile Send private message Send e-mail
athenshorseparty




Joined: 07 Dec 2013
Posts: 5

PostPosted: Mon Dec 09, 2013 11:12 pm    Post subject: Reply with quote

TMC wrote:
Thanks for the testing. Buttons 2 and 10 do work but don't trigger the onkeypress script? I had another thorough look at the code for that, and can see absolutely no explanation. Argh!

Shoot. Well as I said I have a sort of work around that I can build off of. If I can get my hands on a different controller I'll check it out and see if that makes a difference, I'd be really interested to see if anyone else who has a controller gets different results.

Quote:

Yikes! Does this fix itself after you press a key or do other things like switch away and back to the window again? Or do you have to quit and restart the game?

And yeah hardly anyone considers joysticks and unfortunately our joystick support is supposedly bad in places (there are apparently a couple of things which require the keyboard)


You have to quit and restart. The keyboard still works but once you minimize game.exe the joystick cuts out completely, even on the calibration screen.

I'll probably be working on this game for a while, taking my time with it making it really good, there's a lot of stuff I have planned for it so maybe some of these things will be worked out in a new build by then. It's not like I'm going to require people to use the controller, I mainly wanted that option for myself.

I'm gonna be hard-coding every aspect of the game myself: HUD, menus, combat and jumping mechanics (it's gonna be much more Zelda style than Final Fantasy style) and so I'll have a chance to look at and try out a bunch of different things as far as interfacing with the controller. So I'll report back here if new issues arise.

Thanks again for the feedback
Back to top
View user's profile Send private message
TMC
On the Verge of Insanity




Joined: 05 Apr 2003
Posts: 3240
Location: Matakana

PostPosted: Mon Dec 09, 2013 11:38 pm    Post subject: Reply with quote

So does joystick input break only when you use alt+tab, or when you change the window focus in general?

User input (keyboard, mouse and joystick) is handled by the graphics 'backend'. The default graphics backend on Windows is gfx_directx. Could you please try using gfx_sdl instead and see whether that fixes the problem with alt+tab (or perhaps even any of the others)? To switch to gfx_sdl simply remove (or rename) the gfx_directx.dll file before running game.exe. You can check which backend is in use by clicking on the icon at the top left of the window in the window frame: with gfx_directx you'll see an extra "Options" menu item which isn't there with gfx_sdl.
_________________
"It is so great it is insanely great."
Back to top
View user's profile Send private message Send e-mail
Display posts from previous:   
Post new topic   Reply to topic    Castle Paradox Forum Index -> HELP! All times are GMT - 8 Hours
Page 1 of 1

 
Jump to:  
You can post new topics in this forum
You can reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2005 phpBB Group