JavaScript questions that don't deserve their own thread

● ARCHIVED · READ-ONLY
Started by Shaz 3413 posts Page 107 of 171 View original ↗
  1. ScorchedGround said:
    @retrofiction

    To invert a condition, simply put a "!" in front of the statement you wish to reverse.

    So in your case;

    JavaScript:
    if (!$gameVariables.value(140).includes('28')) {
        //stuff
    }
    Thank you!
  2. The not operator (!) is probably the simplest solution.

    Code:
    if (!$gameVariables.value(140).includes('28'))
    {
    do something
    }

    EDIT; apparently I need to read a few posts after the first one I haven't seen!
  3. Not sure if this fits here. It seems similar enough.

    In RPG Maker MZ's code, where are the lines of code that add the skill selected by the player on the battle screen to that player's action array and change BattleManager._phase? I can't seem to find them and I need to change what that does.

    For reference, somewhere in the code, BattleManager._phase is changed from "input" to "turn". I can follow the code to where the below code gets called, but I don't understand much beyond that. It's also possible I followed the wrong lines of code and have ended up on a wild goose chase. Any help would be greatly appreciated.

    Code:
    Game_Troop.prototype.updateInterpreter = function() {
        this._interpreter.update();
    };

    That's lines 5877-5879 of rmmz-objects.js

    Edit: What I mean to say is that the function GameTroop.prototype.updateInterpreter gets called. Not that it gets defined at that point. So in other words,
    Code:
    this._interpreter.update();
    is called and then things stop making sense to me.
  4. Fish767 said:
    Not sure if this fits here. It seems similar enough.

    In RPG Maker MZ's code, where are the lines of code that add the skill selected by the player on the battle screen to that player's action array and change BattleManager._phase? I can't seem to find them and I need to change what that does.

    For reference, somewhere in the code, BattleManager._phase is changed from "input" to "turn". I can follow the code to where the below code gets called, but I don't understand much beyond that. It's also possible I followed the wrong lines of code and have ended up on a wild goose chase. Any help would be greatly appreciated.

    Code:
    Game_Troop.prototype.updateInterpreter = function() {
        this._interpreter.update();
    };

    That's lines 5877-5879 of rmmz-objects.js

    Edit: What I mean to say is that the function GameTroop.prototype.updateInterpreter gets called. Not that it gets defined at that point. So in other words,
    Code:
    this._interpreter.update();
    is called and then things stop making sense to me.

    I found the answer. The lines of code that handle when the player selects a skill on the battle tree are located on lines 3465-3471 of rmmz_scenes.js. If you want to find other commands you can control F and search for setHandler. Each setHandler function sets up a button that the user should be able to click. Then you can find out what function is being set in the set handler function and search for that in the files. Here's an example:
    JavaScript:
    this._actorWindow.setHandler("ok", this.onActorOk.bind(this)); //line 3259
    
    //maps to lines 3411-3416
    
    Scene_Battle.prototype.onActorOk = function() {
        const action = BattleManager.inputtingAction();
        action.setTarget(this._actorWindow.index());
        this.hideSubInputWindows();
        this.selectNextCommand();
    };

    From there you can edit the function to add whatever neat functionalities you need for your game. I recommend doing that in a plugin though.

    In my case, the code that pushes the action into the array is the same code that changes "input" to "turn" which means I don't have to do any extra searching. Yay!
  5. I'm trying to teach myself javascript and going through some plugins and the original RPG Maker MV code line by line and I can't figure out where the setHandler() method is declared or what it fundamentally is. I can figure out how it's used and how I would duplicate it if I wanted to add input functionality to a scene, but I don't understand where this method came from. What/where is it?
  6. OKIComputer said:
    I'm trying to teach myself javascript and going through some plugins and the original RPG Maker MV code line by line and I can't figure out where the setHandler() method is declared or what it fundamentally is. I can figure out how it's used and how I would duplicate it if I wanted to add input functionality to a scene, but I don't understand where this method came from. What/where is it?
    I only have access to MZ, but the setHandler function in MZ was declared in the rmmz_windows.js file on line 1028. I assume it would be in rmmv_windows.js on a nearby line, but I can't confirm that.

    A handler is a function attached to an object that can be called with other functions. So a setHandler() sets the function, and in MZ's case, the callHandler() would call the function (I think). That's my very basic understanding of how they work.

    Handlers allow programmers to change a function on the fly which is useful if you are using classes. Handlers allow each object created from a class to have different functions with the same name which makes calling them easier and more consistent. In MZ's case, a different function gets applied to the options the user can select depending on what that option represents. The setHandler() makes the attack button perform the attack function instead of the guard function. It's possible to do it a different way with one huge function, but that is inefficient as you would need a lot of if statements. That is my very basic understanding of why they are useful.
  7. retrofiction said:
    How do I check if an array does NOT include a specific value?
    NOT is !
    retrofiction said:
    JavaScript:
    if (!$gameVariables.value(140).includes('28'))

    Lol, for some reason the thread loaded at the top of the page and I didn't notice it had been answered twice. Sorry!


    OKIComputer said:
    I'm trying to teach myself javascript and going through some plugins and the original RPG Maker MV code line by line and I can't figure out where the setHandler() method is declared or what it fundamentally is.
    You should be able to just go to the js folder in Windows and type "prototype.sethandler" into the search bar. That brings up rpg_windows.js, so you open that in your text editor and search for "prototype.sethandler" - that shows you where it's declared.
  8. .
  9. RianQuenlin said:
    How can I count the length of a variable excluding leading zeros and apply it to a variable? As in 594512 would return 6, and 5910395 would return 7.
    number.toString().length

    e.g. $gameVariables.value(5).toString().length

    As for the leading zeros bit...a numeric variable won't/can't have leading zeros, it would already have to be a string. So you'd turn it into a number, back into a string, get that length.
  10. RianQuenlin said:
    How can I count the length of a variable excluding leading zeros and apply it to a variable? As in 594512 would return 6, and 5910395 would return 7.
    I would actually just do it the way that ATT_Turan suggested, but if you're ever feeling extra fancy, you *could* do it this way instead:

    JavaScript:
    Math.floor(Math.log10(number) + 1);

    adventure-time-finn.gif
  11. .
  12. Is there a script that will give the ID of the last skill used by the enemy?
  13. Lady_JJ said:
    Is there a script that will give the ID of the last skill used by the enemy?
    On MZ (only), you can get the ID of the last skill used with:

    JavaScript:
    $gameTemp.lastActionData(0);

    However, that is the last skill used period, and not specifically the last skill used by an enemy. So it kinda depends on when you're running the script, and what exactly you're trying to do.
  14. Arthran said:
    On MZ (only), you can get the ID of the last skill used with:

    JavaScript:
    $gameTemp.lastActionData(0);

    However, that is the last skill used period, and not specifically the last skill used by an enemy. So it kinda depends on when you're running the script, and what exactly you're trying to do.
    Thank you. I might be able to use that for what I need. Thanks for the advice re: not being able to discriminate whether it was an actor or an enemy skill. I can see how not realizing that would give me a migraine. :)
  15. I have a question regarding regarding MZ and Visustella's Skills and States Core: I am following VisuStella MZ Action Sequence: Creating a Custom Skill Cost System With Variables and Pictures tutorial on the official blog and while I can allow the skill in question be usable only when the gauge is full (100 points) I am strugging at putting other limitations, mainly that two characters are in the battle party as I plan to use the gauge to create team attacks. The JS code provided in the tutorial is:
    JavaScript:
    <JS Skill Enable>
     enabled = $gameVariables.value(4) >= 4;
    </JS Skill Enable>

    As far as I can tell
    JavaScript:
    $gameParty.members()[n].isBattleMember()
    is a function which checks if an actor is in the party but that's all I can tell.
  16. $gameParty.members() is already returning an array of the members of the party in battle, so rather than do the extra stuff if you just add ".length" that will get you the number of actors in the battle. eg.

    Code:
    enabled = $gameParty.members().length > 1
  17. Hello, I am a VERY NEW newbie to JS and such. I am doing research to learn how to navigate it better but I am trying to make my first game in RPGmaker (fun personal project only).

    I need to input a variation of this code like.. a hundred different times with minor tweaks here and there to get it work right. Unfortunately I need to convert this common event to code (Preferably JS). I know how to make it work math wise but don't know how to actually input commands into JS.

    I would appreciate any help or just a quick code translate so I know how to que up things like variable/switch creation/changes as I would eventually like to make this a separate plugin, but for now just want to test my thing inside RPGmaker.

    Thank you for any assistance anyone is willing to offer and hope you have a great day.
  18. How do I see the list of actions inside queue during a battle in console?
  19. Silva said:
    $gameParty.members() is already returning an array of the members of the party in battle, so rather than do the extra stuff if you just add ".length" that will get you the number of actors in the battle. eg.

    Code:
    enabled = $gameParty.members().length > 1
    I think either I wasn't very clear or you misunderstood: since I want to include team attacks (more like two-character skills) I need to check if specific actors are in battle, like if Actor 1 and Actor 5 are in the active battle party since my game will have more than 4 characters and each pair will have a different skill. I hope that clears things up.
  20. Kaimi said:
    I have a question regarding regarding MZ and Visustella's Skills and States Core: I am following VisuStella MZ Action Sequence: Creating a Custom Skill Cost System With Variables and Pictures tutorial on the official blog and while I can allow the skill in question be usable only when the gauge is full (100 points) I am strugging at putting other limitations, mainly that two characters are in the battle party as I plan to use the gauge to create team attacks. The JS code provided in the tutorial is:
    JavaScript:
    <JS Skill Enable>
     enabled = $gameVariables.value(4) >= 4;
    </JS Skill Enable>

    As far as I can tell
    JavaScript:
    $gameParty.members()[n].isBattleMember()
    is a function which checks if an actor is in the party but that's all I can tell.
    I don't know what code you're using for your gauge, so I'll just pretend that the $gameVariables.value(4) >= 4 part accurately represents your gauge check. In that case, your note tag could look like this:

    Code:
    <JS Skill Enable>
    enabled = $gameVariables.value(4) >= 4 && $gameActors.actor(x).isBattleMember() && $gameActors.actor(y).isBattleMember();
    </JS Skill Enable>

    You would replace x and y with the IDs of the two actors that you're talking about.


    Fionn23 said:
    How do I see the list of actions inside queue during a battle in console?
    Please clarify. Are you talking about the actions of a specific battler? Or the actions of all battlers? Or the actions of a specific range of battlers?