The RPG Maker Resource Kit

RMRK RPG Maker Creation => General Tutorials and Eventing => RPG Maker General => Tutorials Database => Topic started by: D&P3 on April 24, 2012, 03:28:06 PM

Title: [ XP / VX / VXA ] Button Mashing Fix
Post by: D&P3 on April 24, 2012, 03:28:06 PM
This is not a tutorial on how to create a button mashing system, although if you don't know how you can probably pick up the idea of how to in this tutorial.

This is a tutorial on how to fix user input in a 'Button Mashing' event.

The usual method of a implementing Button Mashing event is to create it with a variable count like this
(https://rmrk.net/proxy.php?request=http%3A%2F%2Fimg4host.net%2Fupload%2F241626304f96b8163c2bc.JPG&hash=584f9fd981c4ce6ceef882f2d164e9c60c1f6b74)


However, there is a slight problem with doing it like that. Only the conditions have been set for variable and the key to be pressed.

What is the problem with it, you ask?
With that method, I (the player) could easily hold that button down and it would still continue to add onto the variable counter until it has reached the limit, button mashing means that I have to keep on pressing the button to achieve my goal, not hold it down.

Setting a wait frame on the branch does not change the fact that I can hold the button either.
(https://rmrk.net/proxy.php?request=http%3A%2F%2Fimg4host.net%2Fupload%2F241632464f96b98e85427.JPG&hash=4997b68df86af9394448b5a17323f469d56ad0f7)



Luckily though, there is a way to fix the button mashing issue. However it requires some scripting; do not fear, I shall step you through it.

First things first, you'll need to open up your script editor in your desired RPG Maker and create a new script above 'main' but under 'materials'.
Inside this new script that you just created, paste this code:

Code: [Select]
#==================================================================================
#    This Code Snippet is used to check whether or not you've already
#    pressed a specified key. It is useful if you're using an event which requires
#    the player to do some button mashing, as by default the RPG Maker will
#    allow the player to just hold that specified button to do the job.
#
#
#    It does not do the check by itself, it needs input
#    from the user to begin doing it's checks.
#
#    This means that you can run left and right and hold down any key for
#    as long as you desire unless you've evented the game not to allow for
#    that to happen.
#==================================================================================
module DP3_KeyPressed_Checker
 
  @isKey_Left_Pressed   = false
  @isKey_Down_Pressed   = false
  @isKey_Right_Pressed  = false
  @isKey_Up_Pressed     = false
  @isKey_A_Pressed      = false
  @isKey_B_Pressed      = false
  @isKey_C_Pressed      = false
  @isKey_X_Pressed      = false
  @isKey_Y_Pressed      = false
  @isKey_Z_Pressed      = false
  @isKey_L_Pressed      = false
  @isKey_R_Pressed      = false
 
end

If you take a look at that script, you'll notice how a lot of it says 'isKey_""_Pressed'. This will be the variable that will tell your button mashing event whether or not the player is holding the button that you want them to press, not hold.


This is what your event will look like in the end
(https://rmrk.net/proxy.php?request=http%3A%2F%2Fimg4host.net%2Fupload%2F241648414f96bd49d9756.JPG&hash=83518aee4ffa27bb40d7e5efb9433582038bd762)


Look difficult? Don't understand?
continue reading below.



The event is set up the same way that it normally is; however before your event process's its commands after the player presses C, it goes and checks another conditional branch which has a script call that says
!@isKey_C_Pressed

Let's go through what that means...

The @isKey_C_Pressed is simply checking the variable in the script to see whether it says 'true' or 'false'.
The ! in front of the variable tells the conditional branch to make sure that variable says false before continuing with the commands.

This means that if !@isKey_C_Pressed says 'true', then the conditional branch will not process the commands and instead process any commands in the 'else' statement. Which is nothing.
(https://rmrk.net/proxy.php?request=http%3A%2F%2Fimg4host.net%2Fupload%2F241705324f96c13c1ebfb.JPG&hash=02890f4d56df962c56bfa6c630e577111fbd241e)


So if the variable says 'false' then the conditional branch will process the commands, which as of right now simply says to add +1 to the variable counter,
and then to change the @isKey_C_Pressed variable to say 'true'


If you've been following everything so far, this means that the conditional branch will not process these commands again because that same variable which needed to say 'false' now says 'true'.

This is what prevents the player from holding down that button during the button mashing event.
Once the player stops holding down the 'C' key, the conditional branch will process the other else statement.
(https://rmrk.net/proxy.php?request=http%3A%2F%2Fimg4host.net%2Fupload%2F241722194f96c52b3f8a3.JPG&hash=518b4d30e2dbfae609a57fe9109306e89fcf923a)


Since the conditional branch is processing this else statement, that must mean that the player released the specified button, which means that we can set the @isKey_C_Pressed to say 'false' once again and allow the conditional branch to process its commands again if the player presses the specified key.





If you're not using the 'C' key, you can specify which key you are using by replacing '@isKey_C_Pressed' with '@isKey_<Insert Key That You Are Using>_Pressed'
Title: Re: [ XP / VX / VXA ] Button Mashing Fix
Post by: Mushu on April 24, 2012, 03:53:30 PM
Very nice, I can't wait to make a button mashing event. 8)
Title: Re: [ XP / VX / VXA ] Button Mashing Fix
Post by: modern algebra on April 24, 2012, 04:48:35 PM
It's not a bad thought, but why use any scripting? Couldn't you do the same thing by turning an in-game switch on and off in the same manner as you turn the scripted variables to true or false?

Alternatively, if you did want to use scripting, there are existing methods which allow you to check whether a button has only been pressed this frame. In VX and XP, it is:

@>Conditional Branch: Script: Input.trigger?(Input::C)

In VXA, it would be:

@>Conditional Branch: Script: Input.trigger?(:C)

Also, your module isn't really doing anything - the @isKey___pressed variables are all located in a module, and those values aren't being accessed when you modify the variables with the same name in the Interpreter class. You are just creating new local variables with the same names in the Interpreter class with your code.

That said, I like that you are looking at creative ways to get around some eventing limitations.
Title: Re: [ XP / VX / VXA ] Button Mashing Fix
Post by: D&P3 on April 24, 2012, 06:21:50 PM
It's not a bad thought, but why use any scripting? Couldn't you do the same thing by turning an in-game switch on and off in the same manner as you turn the scripted variables to true or false?
Truthfully, I didn't think of that, and I probably could've saved a lot of time if I had of actually done so.
I'm also pretty conservative of how many switches I use, I try to avoid using another switch for as long as I possibly can.

In VXA, it would be:

@>Conditional Branch: Script: Input.trigger?(:C)
Actually I was attempting that in VXA and kept getting errors.
I didn't realise it had changed to Input.trigger?(Input::C)
which is why I went through all the module variables :-\
Thanks for sharing that info ^-^

Also, your module isn't really doing anything - the @isKey___pressed variables are all located in a module, and those values aren't being accessed when you modify the variables with the same name in the Interpreter class. You are just creating new local variables with the same names in the Interpreter class with your code.
Well that's not the intended effect :-\
I thought it was weird that it worked right off the bat with no problems; but I think I know how to remedy that :)

That said, I like that you are looking at creative ways to get around some eventing limitations.
Thanks for the encouraging words :)
Title: Re: [ XP / VX / VXA ] Button Mashing Fix
Post by: keyhound on August 01, 2012, 04:12:15 AM
Sorry if this is a necropost
but i got an better way(i think) but it doesnt use script and works
 first make the verifier an event that will be kept in a corner of the map
it will only have 1 comand: add 1 to the variable u want to use, it will also have a under hero priority and
be a press button activation type
than when u need the event
get the location of the hero (u can use a save x location and y location on variables)
than teleport the verifier to below the hero and when u get to ur time limit or whatever
teleport him away
in my testing i got an amazing thing i put a limit to the amount of imputs i wanted 10, in this case
in a parallell proccess it had a condition of having 10 imputs ELSE IT would remove 1 imput from the variable
and a wait frame of 10(inside the else, but after the remove)
it was intense, XD I tested having the button pressed but the variable kept decresing
only when i started to mash it rised
another thing u could put is a negative limit of
-20 or even - 50 and something bad happens


sorry for the necro posting but u know, it can really help people, so i figured it was for a good cause...
Title: Re: [ XP / VX / VXA ] Button Mashing Fix
Post by: D&P3 on August 01, 2012, 08:11:15 AM
Nah, you are right. :)

I was supposed to update and fix this topic, but I guess I got lazy.
Title: Re: [ XP / VX / VXA ] Button Mashing Fix
Post by: keyhound on August 01, 2012, 06:58:24 PM
Glad i could help
^^