That's what I have been doing. Running a Common event parallel process with a wait to see if the Shift key has been pressed. But I thought maybe that was too cumbersome. And that I should just literally change what the Shift key does. Because having the background always running to check if the Shift key is pressed to do something else, it just seemed like a bad idea now.
I mean, ATT says it's maybe not the most efficient way to do it, but I personally do it all the time and haven't had problems yet. Someone who knows JS better might be able to find a more efficient way to do it, but I've barely scratched the surface so using a common event is the best way I know how
🙂
What I do (and from what I've seen, at least some other people do as well) is just have one main common event entitled "Main Loop" that I switch on at the start of my game and then just have constantly running as a parallel process. And
everything that I need to be constantly checking or updating, I put in there (unless something requires waiting in-between, which is the only case I make a separate common event for it, because the waiting will hold up the checking/updating of everything else in the Main Loop event, and like ATT mentioned, can lead to missing when the player presses a button if they press it while the "wait" part of the code is running).
So I would
personally recommend this method of doing it. It works, and is easy, so as long as it's not causing visible lag in your game, then I see no reason not to. Now, if you have an extremely complex game with very heavy/cumbersome functions going on in this Main Loop common event all the time, that might be a different story. But it seems like for most people's purposes, it should be fine
🙂
I'm not exactly sure what key mapping is. But reading this, key mapping sounds like an event that auto runs like you said, to change certain keys permanently before the game kicks off. (And then the player plays)
Basically what ATT said! It's just a script call, that's part of assigning a function to a key. It's like you're naming it - although what I called a "name" (such as 'up' or 'alt'), ATT said are actually called "strings".
But it's a two-step process, because once you "name" it, you then have to tell the game what to do when the key by that "name" (i.e. keymapped to that string) is pressed. By default, RPG Maker already has functions associated with those particular strings I had listed out (i.e. 'ok', 'cancel', the four directions, etc.). So if you were to assign/keymap the shift key to the string 'up', for example, it will automatically cause whatever function the 'up' string is associated with (e.g. moving the character up) to happen when the shift key is pressed as well.
You
can do this in the very first event that autoruns at the start of your game (you'd need a plugin to make it run
before the start of the game, like before the title menu). However, you
can also run this same script at any point in the game via any event, and can even re-keymap the key to something different (like, in the middle of the game) after you've already keymapped it before. I just meant to say that that if you run this script at the start of your game (i.e. it's already started, but before the player can do anything or anything else happens), the shift key will have your chosen function from the start of the game, and it will remain unless you manually change it later. Which, in most cases, is what we want!
I don't want the Shift key to become another different key, like Escape. I just want it to run the conditions and branches and choice options or whatever I want for it.
Like in example, I turn it to a "Talk" option, so when the player has a team mate, there is a random talk option (just 1-3 random) when the other team mate follows and comments depending on what map they are on.
Since you want it to do something completely different than any of the default functions built into RPG Maker, then you just have to link whatever "string" you keymapped the shift key to, to whatever common event you want to run when it's pressed.
The Input.keyMapper[<keycode>] = '<string>' script is just the "naming" part. The parallel "Main Loop" common event is where you would check if the key by that "name"/string is being pressed, with the Input.isTriggered('<string>') or Input.isPressed('<string>') script in a conditional branch. Within that conditional branch, you can then call whatever common event you'd like (there's an option to do this directly through the editor, without the need for a script call) 🙂
Like so:
From just those script calls in those events, my game will run the "Draw/Sheathe Weapon" common event whenever the player presses the tab key. Within the "Draw/Sheathe Weapon" common event is where I make whatever I want to happen, well, happen!
I don't know why it's two steps (again, maybe someone with more JS knowledge like ATT would know why), but it just is. For some reason you can't directly use the Input.isTriggered script to check if a specific key (by its JS keycode) is pressed; you first have to "name"/keymap it with the Input.keyMapper script
and then check if whatever key you've given a particular "name"/string is pressed.
I'm not going to pay $10 for that. I don't even pay squat for phone games. lol.
I don't blame you at all, haha! I have it (because for some particular things I want to do it's just more convenient), but I'm pretty sure I didn't buy it. Or if I did, it was sold singly for like a dollar or two. I've had it for a while and I think the forced bundling is recent, which kind of peeves me, but it is what it is. The good news is that the keymapping method pretty much does the same thing... but like I said, it's just a little more work, and requires that Main Loop to be constantly running if you (like me) don't know JS enough to figure out another way. But again, I've never had problems with it yet. There might be a "better" way, but this isn't a "bad" way.
I have my common events set up, and I can now edit the javascripts in the JS folder.
I figure it's just a matter of typing the code into one of those scroll icons?
So you've been able to open the .js file(s) with Notepad?
Just a quick caution: Most people recommend against directly editing and overwriting the .js files, as if it ends up causing problems with your game, there is no backup. I think where ATT was going with this (and ATT please correct me if I'm wrong) is that you can
find the code you need to use in these files (it's where all "script calls" come from that you see people sharing online); but if you want to alter it in any way, it's safest to copy & paste the snippet of code you need into a
new Notepad document, and then save it as a separate .js file.
How to do that:
Spoiler
All you have to do is "Save As", and literally just add ".js" to the end of the file name, and voila, it's a new .js file! Also known as a "plugin", which you've just made!
😉 So now you would take this new file/plugin and place it into the "plugins" folder that lives inside the original "js" folder. Then open RPG Maker and open your plugin manager, double-click on an empty line to add a plugin, there will be a dropdown menu that shows every plugin in your "plugins" folder, and you just choose the one you want to add. Then confirm and you'll see it in the main plugin manager list. Make sure it's "ON", confirm again, and it should work automatically!
The relevance of this, I think, is that it would replace the keymapping that I did in that first autorunning event. So
instead of running the keymapping script once at the beginning of your game, you can put that script in a new .js file/plugin as described above, plug it into your game, and it
should work the same way (you still need the parallel common event to check if the key is pressed - this would only replace the initial keymapping/"naming" part). And since we've given you the exact script calls you need, there really shouldn't be any reason you'd have to go looking through the existing, main .js files to find it -
I don't think.
@ATT_Turan Can you confirm if it's truly as simple as putting the Input.keyMapper[] script calls directly into a new plugin and it should work, or does the code need to be more complicated to work as a plugin?
The reason I don't do it this way is because, as a plugin (which is in constant effect as long as it's on), it really would make the keymapping permanent throughout the entire game, and I personally have reasons I'd want to change my keymapping mid-game (e.g. temporarily disabling functions, repurposing keys based on context, allowing players to configure their own keys, etc.). Therefore, I use the once-and-done method by just using the script call in events. But if you just want it to stay the same through the entire game, then either method should work.
~~~~~
Anyway, I hope I haven't overwhelmed with information again, so that's why I hid the last bit that was only tangentially related (as using .js files is just an alternate method) in a "spoiler". IMO you might at least try out the method I described in the main part of this response (using only script calls in events) first, just to experience what these script calls do and make sure you understand how they work together, before complicating it with the whole making-it-a-plugin thing. It's actually pretty simple taken one step at a time, but with this much new info, human brains can only learn and conceptualize so much all at the same time haha. So I tried not to get too off-track outside of the "spoiler".
Any other questions? Still any specific points of confusion? Or anything that you're trying but isn't working quite right?