RMMV Simple code for telling a switch to turn on when a certain key is pressed

breadpan

Warper
Member
Joined
Jun 14, 2021
Messages
3
Reaction score
0
First Language
English
Primarily Uses
RMMV
More specifically, I am trying to figure out how to tell the tileset to change when I press the space bar. I know how to get it to happen when I go over an event tile but I want it to happen when I press the space bar at any point. Any tips?
 

alltheyuriz

They System is overrated
Veteran
Joined
Sep 18, 2020
Messages
390
Reaction score
234
First Language
English
Primarily Uses
RMMZ
You could use a conditional branch for that couldn't you?
 

Drakkonis

Veteran
Veteran
Joined
Mar 5, 2021
Messages
205
Reaction score
155
First Language
English
Primarily Uses
RMMZ
Here's a decent resource for "converting" event commands into script calls:
RPG Maker MV/MZ Script Calls

In this instance, you want "$gameSwitches.setValue(num, true/false);". You'll put the switch number you want for "num", and true for on, false for off.

EDIT: I just read more specifically what you wanted. For keypress triggers I don't know off the top of my head. I know there IS key detection in script, but MV/MZ only bind functions to certain keys by default. You'd need a plugin to use other keys, I don't think spacebar is one MV/MZ uses. I remember seeing one like that floating around awhile ago, but I can't remember what it was called or where I saw it.
 
Last edited:

Andar

Veteran
Veteran
Joined
Mar 5, 2013
Messages
33,325
Reaction score
8,383
First Language
German
Primarily Uses
RMMV
there is no "simple" code for what you want, because you are asking for three different things.

There is a simple javascript code to change a switch or the tileset directly, you can find that code in the list for script equivalent of the event commands.

There is also a code to check if a specific key or button has been pressed - it works a little different than you seem to assume, but can be used like that.

The problem is the third part - connecting the two and make them constantly check. If you try to use javascript that will require a full plugin to integrate into an update method and check and change what you want.


However I would suggest NOT using javascript at all - use a parallel process event for checking buttons.
That will have the problem that the conditional branch only checks for a limited set of keys, and that it might add to lag if done wrong (you'll need a good number of waits, probably 5 or so).
But it would still be easier for you to do that way.
 

ATT_Turan

Forewarner of the Black Wind
Veteran
Joined
Jul 2, 2014
Messages
1,302
Reaction score
692
First Language
English
Primarily Uses
RMMV
There's Yanfly's Button Common Events plugin which does this, but it's a paid plugin. I don't know if anyone has written a free equivalent.
 

breadpan

Warper
Member
Joined
Jun 14, 2021
Messages
3
Reaction score
0
First Language
English
Primarily Uses
RMMV
there is no "simple" code for what you want, because you are asking for three different things.

There is a simple javascript code to change a switch or the tileset directly, you can find that code in the list for script equivalent of the event commands.

There is also a code to check if a specific key or button has been pressed - it works a little different than you seem to assume, but can be used like that.

The problem is the third part - connecting the two and make them constantly check. If you try to use javascript that will require a full plugin to integrate into an update method and check and change what you want.


However I would suggest NOT using javascript at all - use a parallel process event for checking buttons.
That will have the problem that the conditional branch only checks for a limited set of keys, and that it might add to lag if done wrong (you'll need a good number of waits, probably 5 or so).
But it would still be easier for you to do that
Thanks. Your suggestion was right on the money. It took some trial and error but I figured out the right combination of 5 frame waits and 30 frame waits with a parallel process on a conditional switch.
 

Latest Threads

Latest Posts

Latest Profile Posts

starting working on the sprites for one of my games major antagonists finally. here's the first frame of his chanting motion in battle.
Have spent too much time hammering out with a friend just how to make a reoccurring enemy that permanently learns skills you use against her.
I know what I want in a loose sense. Maybe I should just make a post asking for opinions and suggestions.
Shoot Enemy Off-Screen, Run RPG Maker Game as a Web Server, & Thai Keyboard | RPG Maker News #109

Some people have too strong of an opinion about what maker is the best, I've seen discussions like:
- I prefer VXAce because I like the style of the RTP better than the older releases
- You're worse than Hitler

Forum statistics

Threads
113,734
Messages
1,077,034
Members
147,761
Latest member
Krunkathos
Top