Event on button press

Hi!

Is it possible to have an event start on button press?

I have learnt through this forum how to do a conditional branch for 'if button is pressed' (for player running), but would now like to see if it is possible to activate an event if a button is pressed once and then deactivated if it is pressed again.

Eg. the player is a normal sprite and then if button G is pressed, it changes the sprite to the player holding a sword.

Not sure if this is a conditional branch for 'if button is pressed'?
By default RMXP only support a very limited number of keyboard input.
Thus, a script to support a full keyboard input may be needed.

After that, you just put it in a common event that runs in parallel
And do something like ...
condition script: Input.press?(Input::UP) #this means if up key is pressed.
Do something here...

If you want to force start an even on the current map.
Just use:
wishlist my game below.
Wait, that's not the correct copy-paste message.


Just use:
$game_map.events[PUT YOUR EVENT ID HERE].start

So...
Let's try this
if Input.press?(Input::UP) $game_map.events[1].start end
In a parallel event or a common parallel event.
When the up key is pressed, the no.1 event of this map will fire.
Self Resolved - answer underneath this post

Hi Orochi2K!

You seem to have all the answers!

So this works fine, thank you.
However, is there a way to have it deactivate again with the same key?

I currently have a common parallel and a common with the following:

1)
Conditional Branch: Script: Keys.press?(D)
Set Move Route: Player
: $>Change Speed: 6
Wait for moves completion
Call common event 2

2)
Conditional Branch: Script: Keys.press?(D)
Set Move Route: Player
: $>Change Speed: 4
Wait for moves completion
Call common event 1

But it just crashes saying maximum number of common events error.

Essentially what I am trying here is when you press D, it makes you run and then if you press it again, it makes you walk.

Resolution

I found that putting another conditional branch inside the first branch and have it as Keys.toggle?(D) and then change speed back to 4 worked, no need for a 2nd common event!
Whenever you want something on and off, it's likely the time to use a switch.
You can use RMXP's switch in script by calling:
$game_switches[THE ID OF SWITCH] = true / false

Original thread: https://forums.rpgmakerweb.com/threads/event-on-button-press.133941/