I have a minigame system that goes off button presses. It tells you things like "Press Up!" and "Press Shift!"
Input.dir8 != 0 and !Input.trigger?(Input::UP) works for the 4 / 8 directional movement system. But when I want to do a Shift or Q key, I'm stumped.
What is the line of code to make sure a player is pressing a button, but not pressing the right one?
Night5h4d3
Sep 12 2011, 06:17 PM
I'm on a phone so... Rpg maker > help file > search > input > constants. Hope that helps.
Titanhex
Sep 12 2011, 06:45 PM
That's the first place I went, and how I found the Input.dir8 But there is nothing in there that mentions how to do a check for any button press.
If the player presses W when he should press Space there is no penalty. Only if he presses any of the direction keys. I want to make it so there's a penalty if he presses any button.
Night5h4d3
Sep 12 2011, 06:59 PM
At the bottom of that page you'll see a tab called 'Constants' in bold are the keys you can check for press.
Titanhex
Sep 12 2011, 08:29 PM
So you're saying I have to do like 150 different lines of !Input.trigger?(Input::BUTTONWHATEVER) if I want to check if the wrong button is being pressed plus one for if the right button is being pressed?
I wanted it to make a sound and force you to wait if you pressed the wrong button.
Night5h4d3
Sep 13 2011, 06:07 AM
you don't need to include handling for every incorrect option, instead have something like:
CODE
unless Input.trigger?(Input::BUTTONWHATEVER) # this means unless the correct button was pressed, which means ANY other button will trigger this condition #beep here #wait here #whatever for the wrong condition else # this is in case the correct button was pressed # do something good end
Titanhex
Sep 13 2011, 06:27 AM
But won't that also trigger if no button is being pressed? At least, it does on all my tests.
Night5h4d3
Sep 13 2011, 06:39 AM
Right you are, lemme see, I'll write you up a little snippet. It shouldn't take more than a few minutes.
Titanhex
Sep 13 2011, 06:51 AM
QUOTE (Night5h4d3 @ Sep 13 2011, 08:39 AM)
Right you are, lemme see, I'll write you up a little snippet. It shouldn't take more than a few minutes.
Hehe, thanks. Now you see my dilemma
Night5h4d3
Sep 13 2011, 07:09 AM
you're telling me, it takes actually trying this out for me to remember how notorious ruby is for disliking tertiary expressions. So here it is:
Night5h4d3's Any Input Script
CODE
#============================================================================== # ** Night5h4d3's Any Input Script #------------------------------------------------------------------------------ # Date: 09/13/2011 For: Titanhex #============================================================================== # Descr: # Checks for any input other than specified, returns true if found, returns # false if the correct button is pressed, and returns "noinput" if no input # was detected. #============================================================================== module Input ANY = [Input::UP, Input::DOWN, Input::LEFT, Input::RIGHT, Input::A, Input::B, Input::C, Input::X, Input::Y, Input::Z, Input::L, Input::R, Input::SHIFT, Input::CTRL, Input::ALT, Input::F5, Input::F6, Input::F7, Input::F8, Input::F9] def self.trigger_other?(input) for i in 0...ANY.size if Input.trigger?(ANY[i]) if input == ANY[i] return false end return true end end return "noinput" end end
The way you use this is you call it like a normal input call, sort of:
CODE
if Input.trigger_other?(Input::A) == true # this is handling for incorrect input elsif Input.trigger_other?(Input::A) == "noinput" # put handling here to return up and check again else # this is handling for correct input end
And to boot, here's how you can do it with conditional branches:
Titanhex
Sep 13 2011, 08:13 AM
I assume this wouldn't work for scripts that allow extended inputs?
Also I think you have some typos in your code, possibly here:
ANY = [Input::UP Input::DOWN, Input::LEFT, RIGHT, Input::A, Input::B,
Night5h4d3
Sep 13 2011, 08:27 AM
Unfortunately not, it wouldn't be incompatible, it just wouldn't have handling for the other inputs. and whoops, fixed that. RIGHT was supposed to be Input::RIGHT.
Titanhex
Sep 13 2011, 08:43 AM
Shouldn't Input::UP also be followed by a comma?
That's good that it is still compatible, unfortunate that it doesn't accept other inputs.
Why can't this be aliased into the Input.trigger method instead of creating a new method?
Night5h4d3
Sep 13 2011, 09:55 AM
Looks like I missed that too, XD fixed it in the post.
And simply put, Input.trigger is a hidden def. If I alias it, I've 2 options, call the original before the extra code, or after, doing so before would nulify my code, as the def would have returned by then. and as for before, well, how would I detect if the button was 'triggered?' Because, the code for detecting a trigger is in the same def I have aliased.
The only way of overcoming this issue would be to: A) Know the ruby code for the Input module or B) Create a new def that will call the trigger method separately on all possible inputs Reverse engineering the RGSS dll is the only way to obtain the code for the input module, which is illegal; not to mention that it is written in C/C++, which is not ruby.
Hope that explains why I have to go with method B.
Titanhex
Sep 13 2011, 11:55 AM
Great :3 Thank you kindly.
I believe I understand why you do it in style B. Makes sense to me now.
This is a "lo-fi" version of our main content. To view the full version with more information, formatting and images, please click here.