JavaScript questions that don't deserve their own thread

● ARCHIVED · READ-ONLY
Started by Shaz 3413 posts Page 113 of 171 View original ↗
  1. ATT_Turan said:
    That sort() syntax you're referencing is a JavaScript method for arrays. The skillWindow isn't an array, it's its own Object of type Window_SkillList.

    You can try applying that to the portion of the window's data that is an array. Try modifying the makeItemList() method from rpg_windows.js:
    Code:
    Window_SkillList.prototype.makeItemList = function() {
        if (this._actor) {
            this._data = this._actor.skills().filter(function(item) {
                return this.includes(item);
            }, this);
            this._data.sort((a, b) => $dataSkills[a].mpCost-$dataSkills[b].mpCost);
        } else {
            this._data = [];
        }
    };

    See how that works.
    Thank you! It works like a charm! But I need to remove $dataSkills to be like this.
    JavaScript:
    this._data.sort((a, b) => a.mpCost - b.mpCost);
    Anyway Thank you!!!
  2. What's the correct way to make a state change the affected actor's SV battle coodinates?
  3. Flame_Effigy said:
    What's the correct way to make a state change the affected actor's SV battle coodinates?
    Try calling the startMove() method from a state using a Custom Apply Effect from Yanfly's Buffs & States Core.
  4. Would would change the actor's actual position? Or would that just change how much they step forward at the start of their turn?
    Essentially I have a state and when applied I want the affected actor to move to a selected point on the screen and stay there until the state is removed.
  5. Hello, I'm using the plugin VictorEngine - Fog and Overlay plugin for adding fogs to maps. I like this one because of the notetag script directly onto maps, I'm trying to have fog, but only on a certain part of the map.

    Capture.PNG

    Would it be possible or do I need another plugin?
  6. Hello, I want to do a sort array like this
    JavaScript:
    //Old
    let arr = [0,15,2,0,1];
    //to be like this
    [15,2,1,0,0]

    For sort 0 to last I already got it with this
    JavaScript:
    arr.sort(function(a, b) {
        return (a==0)-(b==0) ||-(a<b);
    });
    //but the order will become like this.
    [1,2,15,0,0]
    
    //I want it to be like this
    [15,2,1,0,0]

    Anyone have any suggestions?
  7. poppicha said:
    Hello, I want to do a sort array like this
    JavaScript:
    //Old
    let arr = [0,15,2,0,1];
    //to be like this
    [15,2,1,0,0]

    For sort 0 to last I already got it with this
    JavaScript:
    arr.sort(function(a, b) {
        return (a==0)-(b==0) ||-(a<b);
    });
    //but the order will become like this.
    [1,2,15,0,0]
    
    //I want it to be like this
    [15,2,1,0,0]

    Anyone have any suggestions?

    For descending order, you could do:
    JavaScript:
    arr.sort((a, b) => b - a);
  8. Oh, Sorry for being not show clear example ;_;
    I don't mean to sort decending order
    this array in my game is character slot (actorId)
    New array example is like this
    JavaScript:
    //the number is actorId & 0 means no actor in that slot
    battleMember = [0,15,0,11,21,2,1,8];
    
    //be like this.
    [15,11,21,2,1,8,0,0];
    Consider changing the order to the previous position but keep the same back/front order
    something like that.
  9. poppicha said:
    Oh, Sorry for being not show clear example ;_;
    I don't mean to sort decending order
    this array in my game is character slot (actorId)
    New array example is like this
    JavaScript:
    //the number is actorId & 0 means no actor in that slot
    battleMember = [0,15,0,11,21,2,1,8];
    
    //be like this.
    [15,11,21,2,1,8,0,0];
    Consider changing the order to the previous position but keep the same back/front order
    something like that.
    Sorry, I didn't read your original post carefully enough. If I'm understanding correctly, you want to keep the non-zero digits in the same order, but you want to move all the zeroes to the end? If so, this should work:
    JavaScript:
    battleMember.sort((a, b) => {
        if (a == 0)
            return 1;
        if (b == 0)
            return -1;
        return 0;
    });

    *edit* The code I had posted wasn't compatible with all browsers. Now it is fixed.
  10. Umm... It's not working...?
    uummm.png
  11. poppicha said:
    Umm... It's not working...?
    View attachment 247107
    Sorry. The way I was doing it works fine on Firefox, but apparently it fails on Chrome. Try this one instead:
    JavaScript:
    battleMember.sort((a, b) => {
        if (a == 0)
            return 1;
        if (b == 0)
            return -1;
        return 0;
    });

    I'm going to edit my other post, to prevent anyone else from being mislead in the event that they stumble across it.
  12. It's work! Thank you very much!
  13. Cynwale said:
    Hello, I'm using the plugin...
    Hi, there! From the first post in this thread:
    Shaz said:
    If you need help getting a plugin working, please start a NEW thread and include a link to where you downloaded the plugin from.

    You're not asking anything about JavaScript directly.

    However,
    Cynwale said:
    Would it be possible or do I need another plugin?
    Per its description, the Victor plugin creates an overlay, which is an image that gets applied to the screen. You would need to look for some other kind of effects plugin to display it to selective portions of the map.
  14. -Made a new topic as per topic rule

  15. Hi, I'm slowly getting back to things and I was going over some older scripts. I noticed a lot of the time, I will have script calls called from Scene_Base to do tasks for everything. I guess cause it's easier to call Scene_Base."function name" for script calls, and was wondering if that's really an optimal way to go about things?

    Was also curious about how most people reference scene's like scene_battle. My work around was to have the scene set a "$sceneBattle" variable to itself when it starts up. And was wondering again if there might be a more optimal way to reference scenes in general. Sorry if it's a dumb question.
  16. sleepy_sealion said:
    I noticed a lot of the time, I will have script calls called from Scene_Base to do tasks for everything...was wondering if that's really an optimal way to go about things? Was also curious about how most people reference scene's like scene_battle.
    It's not a dumb question, but I'm not sure I entirely understand what the question is. So I'll give a bit of an explanation, and hopefully it will answer your question, and if not it will allow you to reword yourself more clearly.

    These words you're referencing (Scene_Base, Scene_Battle) are just JavaScript Objects. An Object is a data type you can use (declare variables of) that contains other things, like variables and methods (contained functions).

    So, for example, if you create let thisScene = new Scene_Base you can then reference thisScene.x for that scene's x coordinate.

    Scene_Battle, and all the other scenes in RPG Maker, are inherited from Scene_Base. That means that they will automatically have all of the properties of a Scene_Base unless you define a new version for that specific type.

    So you could create an "x" method for Scene_Battle that didn't return x coordinates but some other value. In this specific example, that would be pretty silly, but it's the general idea.

    You can open up the rpg_scenes.js file and just read through it to see examples. One of the best ones is the create() method. You'll see Scene_Base's create() method is empty, because you never actually create a scene of the type Scene_Base. All the other scenes have their own create() method that creates the specific windows that make up that scene.

    So I suppose a possible answer to your question is you would rarely/never want to specifically call a function from Scene_Base. You would pretty much always want to use the method that's a part of the actual scene you're in now.
  17. Edit: Making a new thread as per thread rules.
  18. sleepy_sealion said:
    Hi, I'm slowly getting back to things and I was going over some older scripts. I noticed a lot of the time, I will have script calls called from Scene_Base to do tasks for everything. I guess cause it's easier to call Scene_Base."function name" for script calls, and was wondering if that's really an optimal way to go about things?

    Was also curious about how most people reference scene's like scene_battle. My work around was to have the scene set a "$sceneBattle" variable to itself when it starts up. And was wondering again if there might be a more optimal way to reference scenes in general. Sorry if it's a dumb question.
    Like ATT_Turan said, there shouldn't be a lot of scenarios where you're directly calling methods from Scene_Base, but without seeing actual examples of what you're talking about, it's hard to say for sure whether what you're doing is right or wrong. But generally speaking, the only time you should be doing that is when you're creating your own scene, and you want to add additional code to a method that was inherited from Scene_Base. For example:

    JavaScript:
    Scene_Title.prototype.update = function() {
        if (!this.isBusy()) {
            this._commandWindow.open();
        }
        Scene_Base.prototype.update.call(this);
    };

    As far as referencing the battle scene and whatnot goes, you can usually just use SceneManager._scene to reference the current scene, since any time you're going to be trying to reference an instantiated scene object, it's probably going to be the currently active scene. But it still really shouldn't be a super common thing for you to be referencing instantiated scene objects from outside of the scene itself (in which case, you'd just need to reference it with this).

    If you're going to do things like setting it to a global $sceneBattle variable, then you also need to make sure that you clear that reference (i.e. $sceneBattle = null;) when the scene is done, otherwise the garbage collector won't be able to free up the memory that the scene was using.

    DrBuni said:
    SRD_HUDMAKER always spawns in a very unfortunate position. I tried moving it around with windows + shift + arrow keys, but it never leaves the top of the screen. The plugin basically became non-functional at this point. Even if I disconnect my second monitor, it still spawns weird in the main monitor. Please, help me.
    A question regarding a specific plugin always deserves its own thread.
  19. Thanks for the tips guys! I guess I'll stop trying to use Scene_Base then for everything. For an example though, I was hoping I could use it as an quick way to code out stuff from the same place, Like for example:
    Code:
    Scene_Base.restoreMovementDefaults = function() {
     $gamePlayer._moveSpeed = 4;
     $gamePlayer._through = false;
     $gamePlayer._walkAnime = true;
    };
    Though I guess it would be simpler to just have $gamePlayer call that one in particular.

    I was trying out just having functions that don't belong to an object, but I do remember hearing that it's not ideal. I think I'm just over complicating things again. But I guess the kind of goal was to create a "core" script that I could easily call all these functions and stuff.
    Spoiler
    Illustration2.png
  20. sleepy_sealion said:
    For an example though, I was hoping I could use it as an quick way to code out stuff from the same place, Like for example:
    Yeah, that's not a good way to implement that code. If your code has nothing to do with a scene, it shouldn't be contained in a scene.

    If you want to make your own little thing you can call, just write your own function in a plugin file.
    Code:
    function restoreMovementDefaults () {
     $gamePlayer._moveSpeed = 4;
     $gamePlayer._through = false;
     $gamePlayer._walkAnime = true;
    };

    then any time during your game you can simply do a script call restoreMovementDefaults()

    Not everything needs to be associated with a kind of Object, and that definitely shouldn't be associated with an irrelevant Object type.