JavaScript questions that don't deserve their own thread

● ARCHIVED · READ-ONLY
Started by Shaz 3413 posts Page 134 of 171 View original ↗
  1. 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.
  2. @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.
  3. Orugario said:
    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

    Manifest Format - NW.js Documentation
    EDIT: oops someone already answered this, not sure why my browser didnt show the more recent posts
  4. 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
  5. <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
  6. SnakeBD said:
    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
    SnakeBD said:
    ActorId + 1 == 1){
    to ever be true.
  7. 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?
  8. @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.
  9. 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?
  10. AmVa said:
    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:
    caethyril said:
    ◆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.
  11. AmVa said:
    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.

    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();
    };
  12. How do I add a menu command to the overworld menu that calls a common event?
  13. @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).
  14. ATT_Turan said:
    @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.
  15. @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.
  16. 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.
  17. Kes said:
    @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
  18. @FirestormNeos Just to put it out there, at several exchanges you definitely deserve your own thread for help with this :wink:

    And, per the first post of this thread, it is for JavaScript questions, not plugin support.
  19. 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.
  20. AmVa said:
    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.
    Didn't catch this post; I wasn't sure if the audio/parallel events had frozen as well because I didn't have any of those playing on the test map I had the game in whilst experimenting with this.

    At this point I've temporarily resigned on trying to work out a way to implement the desired save system, deleted both addons from the "pluginTesting" project this was all being tested in, and am turning my attention to other matters within the project (ADHD do be like that sometime).