In Pulp the A and B buttons can be scripted to behave as you like, but the d-pad always makes the player move.
I've already battled with changing the default movement on a few different occassions, and I know I am certainly not the first! In those situations I ended up with a specific implementation for the behaviour I wanted, but I thought it would be fun (and maybe even useful) to go one step further and try to make a generic framework for overriding d-pad input in Pulp. This is probably overkill for a lot of use cases, but it may be helpful nonetheless!
My goal was to try and make something as idiomatic to Pulpscript as possible. If pressing the A button triggers the
confirm event, and pressing the B triggers the
cancel event, it would make sense for pressing a direction on the d-pad to trigger its own specific event. Otherwise I wanted an implementation that was as transparent as possible, not limiting use of Pulpscript if at all possible.
Here is what I have come up with:
Overriding Dpad Input Demo.zip (4.9 KB)
The code is heavily commented (hopefully) for clarity, but I'm very happy to answer any questions about it. I'm also very open to any suggested improvements, I'm certain to be missing some tricks!
For this example I re-implemented standard directional movement, with an item that inverts input for a short duration, but you might make the d-pad buttons do just about anything you like.
This is all in the example project, but it's nice to share in the forum right? This is just the actual code that is needed for overriding d-pad input, and I've removed all of my comments for brevity.
on start do config.autoAct = 0 px = event.px py = event.py room = "room" end on loop do skip_detect_dpad_input = 0 frame_player_update_count = 0 end
on update do frame_player_update_count++ if room!=event.room then room = event.room px = event.px py = event.py end call "detectDpadInput" if dpad_input==1 then undoing_move = 1 goto px,py done end if undoing_move==1 then undoing_move = 0 call "processDpadInput" done end px = event.px py = event.py end on detectDpadInput do dpad_input = 0 if skip_detect_dpad_input==1 then done end if frame_player_update_count==1 then if event.dx<0 then abs_dx = 0 abs_dx -= event.dx else abs_dx = event.dx end if event.dy<0 then abs_dy = 0 abs_dy -= event.dy else abs_dy = event.dy end abs_dxdy = abs_dx abs_dxdy += abs_dy if abs_dxdy==1 then dpad_input = 1 call "determineDpadInput" end end end on determineDpadInput do dpad_up = 0 dpad_down = 0 dpad_left = 0 dpad_right = 0 if event.dy==1 then dpad_down = 1 elseif event.dy==-1 then dpad_up = 1 elseif event.dx==1 then dpad_right = 1 elseif event.dx==-1 then dpad_left = 1 end end on processDpadInput do if dpad_up==1 then call "dpadUp" elseif dpad_down==1 then call "dpadDown" elseif dpad_left==1 then call "dpadLeft" elseif dpad_right==1 then call "dpadRight" end end on dpadUp do end on dpadDown do end on dpadLeft do end on dpadRight do end
With the above code in place, scripting behaviour for d-pad input should be as easy as using the player events for each direction button! The events that get triggered are:
You should be free to write any valid Pulpscript in these events. While in the example project I have re-implemented standard movement, you could just as easily have pressing up on the d-pad do something like call
say and make a dialogue box appear.
Despite wanting to make the implementation as transparent as possible I ended up with a few constraints that must be adhered to:
collectevent must be overriden on all item tiles. In the example project I implement a new
pickupevent as a replacement for
Exits cannot be used. In the example project I show how item tiles can be used as exits, but various alternative approaches are possible.
gotois called in a frame without d-pad input, and is targeting a tile adjacent to the player's current position, this may incorrectly get interpreted as d-pad input to be processed. In this specific situation the variable
skip_detect_dpad_inputshould be set to
And possibly more, but hopefully not! Remember that all variables are global in Pulpscript so you must make sure your own don't clash (or change those used in the code).
Hopefully this is of interest to someone. I'm certainly interested in hearing of other ways people have solved this problem, and I am especially interested if anyone has a better solution for detecting d-pad input!