When button Pressed - Conflict.

Hello everyone,


I am having some trouble with the Button Pressed function.


I have two common events that detect for a button being pressed and then change the character sprite if being pressed.


However, if I have both common events running then only the last common event in the list seems to work (I.e only that button press is registered and sprite changed.)


I have a running sprite and an attacking sprtie (for an ABS system)


Shift is pressed for the running sprite.


A is pressed for the attack sprite.


They work independent of each other but not together. So I know its a conflict of the button press as the events themselves work.


Any ideas?
Parallel Processes are tricky, what you should ALWAYS keep in mind is that they are called "parallel" but they are executed one after another. So in your case the sprite you will see is only that for the last executed event.


What I would recommand is to put all the key checks in the same event so you will know exactly how to handle them and in which order. It really doesn't change how your game runs them since they are already running one after another.
Parallel Processes are tricky, what you should ALWAYS keep in mind is that they are called "parallel" but they are executed one after another. So in your case the sprite you will see is only that for the last executed event.


What I would recommand is to put all the key checks in the same event so you will know exactly how to handle them and in which order. It really doesn't change how your game runs them since they are already running one after another.

I thought of this, so I have put both my conditional branches into one common event but I get the reverse of the problem above. It will only do the first button press and not register the second.


It also does not matter where I put the second branch in terms of ELSE (be it the main check or the second one) it does not work.


pressbuttonproblem.png


Ahhh nevermind,


Think I solved it. See picture 2 below.


What I think it was, and I could be wrong, is that I was calling for the button, if it wasn't being pressed then change the sprite back else if the sprite wasnt changed back then check for the second button. What I needed to do was to tell it to check the button press after the first check and if that failed then change the sprite back.


Am I right?


pressbuttonproblem2.png
@Nanaki_Fan Another problem is that you place the conditional checks for button pressed in a way that they're dependent on each other.


It is much more stable if the conditional branches "if button pressed" have the else branches completely disabled (checkbox at the bottom of the window of the conditional branch, remove the mark)) and are executed independently of each other on the main process level of the common event.


Additionally, the way you wrote the second function with button A and the two change pictures, it means that not only the graphic changes only as long as the button is pressed, it also means that the change actor graphic command is executed every single frame in your entire game - it is changed to the second picture every frame when the button is not pressed for example.


This is a way to do this, but you should keep in mind that it will create some lag or remove a good part of the processing resources of the computer even if the lag is not detectable.


If you begin to detect lag, you should change that command sequence into one where the graphic is only changed if the button press is changed, not every frame while the button is pressed and every frame when it is not pressed. That does require a more complex logic with switches to remember the previous state however, and that has other drawbacks.


So it depends on wether lag becomes a problem in the project to decide to do this or not.
If you put it like that of course it doesn't work, what happens if you put it in a if/else statement is this:


- check If condition


- if condition is true? then execute the if branch, if it is false execute the else branch.


That's how it works. If you want your event to process both of them you have to create 2 different if branches (without the else statement). In your example the event will check if the player is running ONLY if the $game_switches[5] (actorfight) is false (OFF).


Another thing: processing both branches doesn't mean it will give tour actor 2 different graphics. The graphic you will see is ALWAYS the last one because the first change craphic command changes acrot graphic, then the second changes it again, what you will see is always the second change. If you want to create a combination of them you have to insert a new combined sprite in a branch that checks if both buttons are being pressed.


And that doesn't solve the problem that it will start the event over and over again, making you character attack more than once if the button is being presed (since your condition checks button press, not button trigger). If you want to avoid something like this I would recommand you to check button press, then increase a given variable (let's say 10 for attack and 11 for the run). Then do something like this:

  1. Button X is being pressed?
      V[10] += 1 and show the animation.
    Else
      V[10] = 0
  2. Button A is being pressed?
      V[11] += 1
    Else
      V[11] = 0
  3. Now both your branches are closed and you have two variables. If both are > 0 it means both you have to execute both your commands (running and attacking) otherwise you have to execute either only a single command or none of them. With this in mind let's proceed:
    (($game_variables[10] == 1) && ($game_variables[11] > 0))   <- This is not a mistake, if V[10] is > 1 it means the button is still being pressed and not triggered.
      display combined animation
    else
      V[10] is 1?
        execute attack animation
      ($game_variables[11] == 0) && (($game_variables[10] == 0) || ($game_variables[10] > 1))   <- This means no button is being pressed OR X is still being pressed
        change actor graphic to the normal one
      V[11] is > 0?
        change actor graphic to the running one
    end

    EDIT: so many changes/answers while I was writing this 😮

Original thread: https://forums.rpgmakerweb.com/threads/when-button-pressed-conflict.71168/