RMRK is retiring.
Registration is disabled. The site will remain online, but eventually become a read-only archive. More information.

RMRK.net has nothing to do with Blockchains, Cryptocurrency or NFTs. We have been around since the early 2000s, but there is a new group using the RMRK name that deals with those things. We have nothing to do with them.
NFTs are a scam, and if somebody is trying to persuade you to buy or invest in crypto/blockchain/NFT content, please turn them down and save your money. See this video for more information.
[ XP / VX / VXA ] Button Mashing Fix

0 Members and 1 Guest are viewing this topic.

*
*crack*
Rep:
Level 64
2012 Best Newbie2012 Most Unsung MemberFor frequently finding and reporting spam and spam bots
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



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.




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



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.



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.



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'
« Last Edit: April 24, 2012, 04:01:53 PM by Chris 3 »
All of my scripts are totally free to use for commercial use. You don't need to ask me for permission. I'm too lazy to update every single script post I ever made with this addendum. So ignore whatever "rule" I posted there. :)

All scripts can be found at: https://pastebin.com/u/diamondandplatinum3

****
Rep:
Level 69
Very nice, I can't wait to make a button mashing event. 8)

*
Rep:
Level 97
2014 Most Unsung Member2014 Best RPG Maker User - Engine2013 Best RPG Maker User (Scripting)2012 Best Member2012 Best RPG Maker User (Scripting)2012 Favorite Staff Member2012 Most Mature MemberSecret Santa 2012 ParticipantProject of the Month winner for July 20092011 Best Veteran2011 Favourite Staff Member2011 Most Mature Member2011 Best RPG Maker User (Scripting)2011 Best Use of Avatar and Signature Space2010 Most Mature Member2010 Favourite Staff Member
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.
« Last Edit: April 24, 2012, 04:52:24 PM by Seamus »

*
*crack*
Rep:
Level 64
2012 Best Newbie2012 Most Unsung MemberFor frequently finding and reporting spam and spam bots
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 :)
All of my scripts are totally free to use for commercial use. You don't need to ask me for permission. I'm too lazy to update every single script post I ever made with this addendum. So ignore whatever "rule" I posted there. :)

All scripts can be found at: https://pastebin.com/u/diamondandplatinum3

**
Rep:
Level 70
RMRK Junior
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...
"To the scientist there is the joy in pursuing truth which nearly counteracts the depressing revelations of truth."
H. P. Lovecraft

*
*crack*
Rep:
Level 64
2012 Best Newbie2012 Most Unsung MemberFor frequently finding and reporting spam and spam bots
Nah, you are right. :)

I was supposed to update and fix this topic, but I guess I got lazy.
All of my scripts are totally free to use for commercial use. You don't need to ask me for permission. I'm too lazy to update every single script post I ever made with this addendum. So ignore whatever "rule" I posted there. :)

All scripts can be found at: https://pastebin.com/u/diamondandplatinum3

**
Rep:
Level 70
RMRK Junior
Glad i could help
^^
"To the scientist there is the joy in pursuing truth which nearly counteracts the depressing revelations of truth."
H. P. Lovecraft