JavaScript questions that don't deserve their own thread

@Orugario - the built-in window.open method recognises a limited set of options, and resizable is not one of those.

For standalone deployments, you can use the NWJS nw.Window.open method instead, which amongst other things recognises a boolean resizable option, e.g.
JavaScript:
if (Utils.isNwjs()) {
  nw.Window.open("https://www.example.com/", { resizable: false });
} else {
  window.open("https://www.example.com/");
}
Hi everyone,

I was wondering if there's a way to modify the "is being repeated" input command in the code.
By default it's something like that : initial input/24 frames delay/6 frames delay.

I would like to modify the 24 frames delay (reduce it). How could I achieve this, and is it possible via script/plugin for flexibility?

Thank you.
@Narch You don't say which RPG Maker you're using. For MV, that's in rpg_core.js:
Code:
Input.keyRepeatWait = 24;
Input.keyRepeatInterval = 6;

Modify either number as you like and either save it as a plugin or call it as a script call in-game.
The strange thing is that a couple of hours ago "resizable=0" was working
This makes me doubt whats actually happening a bit but have you tried "resizable=false" ? That should be correct according to the docs


EDIT: oops someone already answered this, not sure why my browser didnt show the more recent posts
hello, im working with YEP_BattleEngineCore and im trying to make an enemy skill to call an common event depending of the target.

my game only have 4 actors in total and i still cant find a way to detect the id of a enemy's skill target.

so far this is what i have in the script of the skill note:

Code:
<After Eval>

if (BattleManager._action._subjectActorId + 1 == 1){
 $gameTemp.reserveCommonEvent(1);
} else if (BattleManager._action._subjectActorId + 1 == 2){
 $gameTemp.reserveCommonEvent(2);
} else if (BattleManager._action._subjectActorId + 1 == 3){
 $gameTemp.reserveCommonEvent(3);
} else if (BattleManager._action._subjectActorId + 1 == 4){
 $gameTemp.reserveCommonEvent(4);
}

</After Eval>


i tried other things like target.actorId() but nothig (im still new with js in rpgmv)

what would be the best way to do this?

thanks in advance
<AfterEval> provides the target as `target`

so its as simple as :

Code:
<AfterEval>
if(target.isActor()) {
   let id = target.actorId();
  $gameTemp.reserveCommonEvent(id + 1);
}
</AfterEval>
probably dont even need to check if the target is an actor if the skill only targets actors
hello, im working with YEP_BattleEngineCore and im trying to make an enemy skill to call an common event depending of the target.
These notetags are actually from Yanfly's Skill Core, not the Battle Engine - and as @contentdeleted noted, you can simply use "target" (although, it is After Eval with two words, not one like he typed for you).

Why are you adding 1 to your actor IDs? All database IDs start at 1, so it's impossible for
ActorId + 1 == 1){
to ever be true.
I want to set up a system where the same key has 2 functions (regular press and long press).
How do I prevent the "regular press" action from being triggered when the button is long pressed?

I figured I'd need a function that checks if a button is not down this frame but was down last frame, or something along these lines. How'd you go about it?
@AmVa Check out Input.isTriggered() vs. Input.isPressed().

This is easier to do with an event than with code, wherein you have a parallel process that checks isPressed() and increments a variable until you get to the amount of time desired.
The issue is that the "regular press" action is always triggered at any button press, regardless of whether the press ended up being long or not. That's what I want to avoid.

I think the actions should be triggered once the button is not pressed and then check for how long it was pressed in order to separate the 2 actions, no?
I'd need a function that checks if a button is not down this frame but was down last frame
I recently posted this event-based example for doing something once per button trigger:
◆If:Button [Cancel] is pressed down ◆If:#0001 Grenade is OFF ◆Control Switches:#0001 Grenade = ON ◆Text:None, Window, Bottom : :Throw grenade! ◆ :End ◆ :Else ◆If:#0001 Grenade is ON ◆Control Switches:#0001 Grenade = OFF ◆ :End ◆ :End
If what you actually want is to distinguish short & long presses, you can use a similar approach but, as I think you've noticed, you will be limited by causality:
  • You can delay any response until you are certain whether this press is long or not; or
  • Always process press effects, then have long presses add to (and/or undo) that.
Tracking a long press can be done with Input.isLongPressed("ok") (default 24+ frames) or, like Turan mentioned, a variable.
I think the actions should be triggered once the button is not pressed and then check for how long it was pressed in order to separate the 2 actions, no?
I was quite surprised that there is no simple way to check if a key was just released. So I figured I'd just add that, and... well, RPG Maker's logic here really wasn't meant for that to happen, and it proved considerably more complicated than I expected. I had to overwrite Input.update, which could mess with some other plugins that deal with input. But other than that, here's a plugin adding the equivalent of Input.isTriggered() for a key being released. It also returns the number of frames the key was held for, which might help with determining which action to perform.

Spoiler: Plugin
JavaScript:
/**
 * Checks whether a key was just released.
 * @param {String} keyName The mapped name of the key
 * @returns {Number} If the key was just released, the amount of frames it was held for. 0 otherwise.
 */
Input.isReleased = function (keyName) {
    if (this._justReleased.includes(keyName)) return Graphics.frameCount - this._pressedStartTimes[keyName];
    else return 0;
}

void ((alias) => {
    Input.initialize = function () {
        alias.call(this);
        this._pressedStartTimes = {};
    }
})(Input.initialize);

Input.update = function () {
    this._pollGamepads();
    this._justReleased = [];
    if (this._currentState[this._latestButton]) {
        this._pressedTime++;
    } else {
        this._latestButton = null;
    }
    for (var name in this._currentState) {
        if (this._currentState[name] && !this._previousState[name]) {
            this._latestButton = name;
            this._pressedTime = 0;
            this._date = Date.now();
            this._pressedStartTimes[name] = Graphics.frameCount;
        } else if (!this._currentState[name] && this._previousState[name]) {
            this._justReleased.push(name);
        }
        this._previousState[name] = this._currentState[name];
    }
    this._updateDirection();
};
How do I add a menu command to the overworld menu that calls a common event?
@FirestormNeos That's not really a without-a-thread question, as adding symbols and binding commands to the menu is a multi-step process.

Take a look at Window_MenuCommand.prototype.makeCommandList() and follow from there. Otherwise, there are plugins dedicated to doing this (such as DK's Menu Common Events).
@FirestormNeos That's not really a without-a-thread question, as adding symbols and binding commands to the menu is a multi-step process.

Take a look at Window_MenuCommand.prototype.makeCommandList() and follow from there. Otherwise, there are plugins dedicated to doing this (such as DK's Menu Common Events).
ah, okay. I found a plugin (this one) and was able to set up the menu command quite easily by putting "
$gameTemp.reserveCommonEvent(1)" into the "JS Command" box.

However, I think I've messed something up, as when I try selecting the shiny new command I've made, all that happens is the game freezes. Is there a way I can bring up a "here's what's going on behind the scenes" to see in real-time what's causing the freeze? Like, is the system caught in a loop, or is it just waiting for something that's not showing up, or...? If not, maybe someone here could tell me what I'm doing wrong?

For reference, the common event contains nothing but the Plugin command of "AutoSave" for the AES_AutoSave plugin from here.
@FirestormNeos Have you tried bringing up the console? That will show you exactly at what point the engine was no longer able to process the command. Because I have the console always turned on it's been a while since I've had to call it up separately, but iirc it's F8 unless you are using Visustella plugins in which case it is F12.
For reference, the common event contains nothing but the Plugin command of "AutoSave" for the AES_AutoSave plugin from here.
Could always be a compatibility issue between the 2 plugins, but can't tell you for certain without looking into the console.
Anyhow, it'd probably be better to explain what you're trying to achieve exactly, so you might get a better advice which plugin to use.
@FirestormNeos Have you tried bringing up the console? That will show you exactly at what point the engine was no longer able to process the command. Because I have the console always turned on it's been a while since I've had to call it up separately, but iirc it's F8 unless you are using Visustella plugins in which case it is F12.
Console remains empty before & during the freeze, and remains empty when I refresh with F5:
Spoiler
1698284032943.png
@FirestormNeos Just to put it out there, at several exchanges you definitely deserve your own thread for help with this 😉

And, per the first post of this thread, it is for JavaScript questions, not plugin support.
Console remains empty before & during the freeze, and remains empty when I refresh with F5:
Is it a complete freeze (as in, audio and parallel events freezing as well) or just the player input is ignored? in the latter case, it could be an event running somwhere in the background.
Did you try using these 2 plugins separately and see if they work as intended?

Just a guess, but a command like $gameTemp.reserveCommonEvent(1) may not be what this plugin is intended for. Maybe it's reserving this CE indefinitely? Menu commands are usually bound to a function that pushes a new scene, not an event.
Also, the menu scene has no interpeter, which is needed to run plugin commands inside events. There needs to be something in the code that takes you back to the map scene in order for that plugin command to run... so yeah, a lot can go wrong with this setup.

Original thread: https://forums.rpgmakerweb.com/threads/javascript-questions-that-dont-deserve-their-own-thread.46341/