Submit Your Article


 
RPG Maker

Welcome Guest ( Log In | Register )


  Games Resources RPG Maker VX RPG Maker XP Scripts Tutorials Downloads

 
Reply to this topicStart new topic
> No button press. [SOLVED], A line of code to check if a player is pressing anything or nothing?
Titanhex
post Sep 12 2011, 05:26 PM
Post #1


Guru of Water
Group Icon

Group: Revolutionary
Posts: 1,096
Type: None
RM Skill: Masterful
Rev Points: 5




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?

This post has been edited by Titanhex: Sep 13 2011, 11:56 AM


__________________________
Go to the top of the page
 
+Quote Post
   
Night5h4d3
post Sep 12 2011, 06:17 PM
Post #2


The past tense
Group Icon

Group: +Gold Member
Posts: 1,199
Type: Scripter
RM Skill: Undisclosed




I'm on a phone so... Rpg maker > help file > search > input > constants.
Hope that helps.


__________________________
Got 30 minutes? Then you've enough time to play this awesome game:

- potentially promising project page
- thanks holder
My growing space of user-bars:

about me:







I made the following!





Go to the top of the page
 
+Quote Post
   
Titanhex
post Sep 12 2011, 06:45 PM
Post #3


Guru of Water
Group Icon

Group: Revolutionary
Posts: 1,096
Type: None
RM Skill: Masterful
Rev Points: 5




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.

This post has been edited by Titanhex: Sep 12 2011, 06:48 PM


__________________________
Go to the top of the page
 
+Quote Post
   
Night5h4d3
post Sep 12 2011, 06:59 PM
Post #4


The past tense
Group Icon

Group: +Gold Member
Posts: 1,199
Type: Scripter
RM Skill: Undisclosed




At the bottom of that page you'll see a tab called 'Constants' in bold are the keys you can check for press.


__________________________
Got 30 minutes? Then you've enough time to play this awesome game:

- potentially promising project page
- thanks holder
My growing space of user-bars:

about me:







I made the following!





Go to the top of the page
 
+Quote Post
   
Titanhex
post Sep 12 2011, 08:29 PM
Post #5


Guru of Water
Group Icon

Group: Revolutionary
Posts: 1,096
Type: None
RM Skill: Masterful
Rev Points: 5




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? sad.gif

I wanted it to make a sound and force you to wait if you pressed the wrong button.

This post has been edited by Titanhex: Sep 12 2011, 08:32 PM


__________________________
Go to the top of the page
 
+Quote Post
   
Night5h4d3
post Sep 13 2011, 06:07 AM
Post #6


The past tense
Group Icon

Group: +Gold Member
Posts: 1,199
Type: Scripter
RM Skill: Undisclosed




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


__________________________
Got 30 minutes? Then you've enough time to play this awesome game:

- potentially promising project page
- thanks holder
My growing space of user-bars:

about me:







I made the following!





Go to the top of the page
 
+Quote Post
   
Titanhex
post Sep 13 2011, 06:27 AM
Post #7


Guru of Water
Group Icon

Group: Revolutionary
Posts: 1,096
Type: None
RM Skill: Masterful
Rev Points: 5




But won't that also trigger if no button is being pressed? At least, it does on all my tests.

This post has been edited by Titanhex: Sep 13 2011, 06:28 AM


__________________________
Go to the top of the page
 
+Quote Post
   
Night5h4d3
post Sep 13 2011, 06:39 AM
Post #8


The past tense
Group Icon

Group: +Gold Member
Posts: 1,199
Type: Scripter
RM Skill: Undisclosed




Right you are, lemme see, I'll write you up a little snippet. It shouldn't take more than a few minutes.


__________________________
Got 30 minutes? Then you've enough time to play this awesome game:

- potentially promising project page
- thanks holder
My growing space of user-bars:

about me:







I made the following!





Go to the top of the page
 
+Quote Post
   
Titanhex
post Sep 13 2011, 06:51 AM
Post #9


Guru of Water
Group Icon

Group: Revolutionary
Posts: 1,096
Type: None
RM Skill: Masterful
Rev Points: 5




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 wink.gif


__________________________
Go to the top of the page
 
+Quote Post
   
Night5h4d3
post Sep 13 2011, 07:09 AM
Post #10


The past tense
Group Icon

Group: +Gold Member
Posts: 1,199
Type: Scripter
RM Skill: Undisclosed




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:


__________________________
Got 30 minutes? Then you've enough time to play this awesome game:

- potentially promising project page
- thanks holder
My growing space of user-bars:

about me:







I made the following!





Go to the top of the page
 
+Quote Post
   
Titanhex
post Sep 13 2011, 08:13 AM
Post #11


Guru of Water
Group Icon

Group: Revolutionary
Posts: 1,096
Type: None
RM Skill: Masterful
Rev Points: 5




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,


__________________________
Go to the top of the page
 
+Quote Post
   
Night5h4d3
post Sep 13 2011, 08:27 AM
Post #12


The past tense
Group Icon

Group: +Gold Member
Posts: 1,199
Type: Scripter
RM Skill: Undisclosed




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.


__________________________
Got 30 minutes? Then you've enough time to play this awesome game:

- potentially promising project page
- thanks holder
My growing space of user-bars:

about me:







I made the following!





Go to the top of the page
 
+Quote Post
   
Titanhex
post Sep 13 2011, 08:43 AM
Post #13


Guru of Water
Group Icon

Group: Revolutionary
Posts: 1,096
Type: None
RM Skill: Masterful
Rev Points: 5




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?

This post has been edited by Titanhex: Sep 13 2011, 08:46 AM


__________________________
Go to the top of the page
 
+Quote Post
   
Night5h4d3
post Sep 13 2011, 09:55 AM
Post #14


The past tense
Group Icon

Group: +Gold Member
Posts: 1,199
Type: Scripter
RM Skill: Undisclosed




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.


__________________________
Got 30 minutes? Then you've enough time to play this awesome game:

- potentially promising project page
- thanks holder
My growing space of user-bars:

about me:







I made the following!





Go to the top of the page
 
+Quote Post
   
Titanhex
post Sep 13 2011, 11:55 AM
Post #15


Guru of Water
Group Icon

Group: Revolutionary
Posts: 1,096
Type: None
RM Skill: Masterful
Rev Points: 5




Great :3 Thank you kindly.

I believe I understand why you do it in style B. Makes sense to me now.


__________________________
Go to the top of the page
 
+Quote Post
   

Reply to this topicStart new topic
1 User(s) are reading this topic (1 Guests and 0 Anonymous Users)
0 Members:

 

Lo-Fi Version Time is now: 23rd May 2013 - 03:53 PM
RPG RPG Revolution is an Privacy Policy and Legal
eXTReMe Tracker