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:
# 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.
@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
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...
is simply checking the variable in the script to see whether it says 'true' or 'false'.
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
'@isKey_<Insert Key That You Are Using>_Pressed
This post has been edited by diamondandplatinum3: Apr 24 2012, 08:04 AM