Equipment Weight Plugin

So I have been working on and off on this plugin for a while but making no real progress

What is it meant to do:
Each 'Class' has an EquipLoad which determines how much weight they can carry, the plugin set the Limit as decimal multiplier (I'm aiming to use 1.25) and a decimal for EncumberLimit which is the point when they TotalWeight/EquipLoad is greater than will add a state to that actor

Weapons and Armour have a set Weight value (will refer to as equipment from this point)
​
Problems:
First, as far as I can tell it is impossible to compare the weight of two pieces of equipment before changing them, I would prefer not force a fail here as it may not have proper feedback for the player, meaning I have to lock them into the equip menu for that actor until their TotalWeight/(EquipLoad*Limit) is 1 or less

Second, (this may be easier but it alludes me) I want to do an eval for EquipLoad so that it naturally increases with the Actors level, since my plan was to pace this in via 'noteboxing' (<EquipLoad: base + [level-1] * growth>)
[Solved]

Third, I have no idea how to set up Plugin Commands (not that I know if this will help or not)

Forth, haven't worked out how to display weight, AT ALL, I could just add it to the text of equipment but for Actors I either need to display the percentage (TotalWeight/(EquipLoad*Limit)) or also the actual numbers TotalWeight vs EquipLoad*Limit​

What I've done so far is a bit of a mess and I have no idea if anything works since I can't get any info out from it but also not throwing an runtime errors, so I'm at a loss as to where to go

What it looks like: (updated 3/3/18, 11:59pm)
I am using other plugins that will impact this one (Yanfly's EquipCore and MalDuelWield...possible others) but if I can get it to work on its own then I can work out the compatibility issues

I also need to disable 'Optimise' since it will more than likely pick the heaviest equipment, I don't see a work around that either
I also need to disable 'Optimise' since it will more than likely pick the heaviest equipment, I don't see a work around that either
Yanfly's equip core lets you lock optimize for certain equipment types I believe
I get a syntax error when enabling the plugin with a new project and no other plugins.

Many missing closing ")" in the code posted. I recommend using a linter such as ESLint to catch errors. There's probably a plugin available for your JS editor.
RegExp.$1-$9 are non-standard according to Mozilla's web docs.
Extra closing "}" in processEWNotetags3.
There is no "=<" operator in JS. Did you mean the "<=" operator? Might be a good idea to turn off font ligatures as that seemed to visually mask the the error by replacing both the invalid "=<" and valid "<=" operators with the same ligature.
Ok, I got = and < switched around again, the extra "}" was actually caused by an extra "{", then there were a few missing ")"

RegExp$1...$9 is used for "obj.note1.split" with $1 being the first element (according to how the Mozilla doc reads)

Now I just have a new error, "Cannot read property 'split' undifined" which likely means that I am doing my split wrong

currently using: (/[\r\n]+/)

\n is split at new line related, but I'm honestly not too familiar with spliting, and been using similar code from other plugins that read in the similar data

In regards to Yanflys 'Lock Optimise' that just means that equipment type is unaffected by the optimise function, if I locked it for all equipment types (which IS what I would have to do) means that the function will do nothing, and this seems silly to have for the player to become confused and possibly miss lead them into thinking they have the best gear on already seems like bad design that I would prefer to avoid
Ran the latest though ESLint and I got invalid regular expression error. It says there's an unmatched ')' here.

Code:
var note1 = /<(?:EQUIPLOADPLUS):[ ]\d+)>/i;

A variable names tempWeight was defined without var making it global. Is that intended?
Ok, all bugs seem to be fixed (checked with F8), but now comes the problem of getting it to work as intended
Best way to check for errors is to use ESLint or some other linter.

Stop resisting! I mean that in the friendly way. 🙂

Anywho, next oversight comes in though Game_Item.prototype.initialize. It takes an argument, item, but doesn't pass the argument though to the alias.

The updateWeight method has an undeclared variable, capacity, and the createCommandWindow method has 2 undeclared variables named rect and ww1.
Well, did some more cleaning up, starting feel a bit of an idiot for the number of careless mistakes I've been making in this, I don't think Notepad++ can run ESLint but I may be mistaken

Check it with JSLint after doing the last set of fixes, nothing seems wrong now, but with the track record I've developed with this "master piece" I doubt there aren't a few bugs, besides the fact that the Scene_Equip doesn't work and just pops the window to the left hand side instead of the right
Oooooh boy, so I got something to happen, If you remove a weapon in slot on you get two, but equipping consumes two, have no idea whats causing that to happen
Ah, so that explains it. Notepad++ is alright but you want something like Visual Studio Code.

Anywho, next you'll want to learn about the debugger. It can step though code line by line as it executes and it shows the value of variables and just a bunch of other great features. Here's a good video.
Yeah, except when the code riles on RPG Maker to run, cause then the debugger won't know what to do

I've just been using the F8 key to bring up the built in debugger to check for errors since it doesn't seem to have a good stepper or an ability to mark lines to stop on

It may not be obvious from the code I put up but I am a programmer, have been for 7 years now, just let myself get a little rusty with JavaScript
Stop resisting! (Again, in the friendliest way with the biggest smile.)

Toss the code at a linter to catch syntax errors that can cause the file to get dumped.

Click the Sources tab then navigate to the js -> plugins folder and select a file to begin debugging.

Click a line number to set a breakpoint. JavaScript also has a debugger statement.

I'm only an amateur programmer so I don't know how you'd describe an adequate stepper but there are options to step over a function call, in to, and out of the current function which can all be seen at the top of the right most panel.

example.png
Yeah, stepover is pretty common

The problem at the moment is most likely the item object being called twice cause it to subtract and add two of it since I'm passing an item once into my overriding method and then passing it into the original, likely not referring to the same instance (which is weird but the logical explanation)

As for debugging I've been doing manual step through for so long that I've gotten pretty decent at it, the main problem is the built in error catcher for MV is really bad, catching the first instance something goes wrong rather than what actually went wrong, sometimes giving a cryptic clue
OK, ended up recoding it, so a lot of name changes to things happened but I found two useful tools that helped narrow in on the problem
console.log(x) : prints 'x' to the console so I can use this to check what values a variable has
alert(x) : opens an alert window that displays 'x', I'm using this to show the return of a method​

So my note tags are being read properly, the problem is that the new variables I'm creating aren't being defined, I can only guess that "DataManager" runs before any "initializers", but either way, since the note values aren't being passed to the objects they end up undefined which is why nothing is working as intended

Now I just need to work out how I create new object/class variables for the note tags to pass their data into
Why would you need to have found console.log()? It was covered in the video I linked to back in December. That was like 1,663 hours ago. The video is 61 minutes long meaning it could have been seen a thousand times by now. If you weren't able to watch the video I would be happy to write up the highlights if you need. I know some places don't have good Internet access.

What's with all the processing with the note tags? I ask because nothing special seems to be going on. Note tags are processed by the game engine making it easy to pull the data from an actor's or item's meta property. For example, if we wanted the Max Load of an actor we could write $dataActor[1].meta["Max Load"] which returns a string but that's easy enough to change to a number using the Number() function.
Log videos with lots of padding are hard to sit through, its easy to get to the point then reading through pages and pages to find one thing

As for processing the note tags in such away it means that they are permanently stored in RAM during the rather than opening and closing the file constantly (in other words, it saves time), this method also means the note tags can be more flexible in their format (not case sensitive)
I don't understand your first sentence. If you had watched one minute of video per day then then numbers say you would have finished it one time by now. If you had written notes on the parts you wanted to remember then you would have easy access to just those bits.

My point is that note tags are already processed and in memory and your code is duplicating that work. Your argument that doing the same thing twice is faster doesn't make a lick of sense and that's beside the fact that your code doesn't do file access so there's no reason to bring that up in the first place.

Write a function that pulls the data from the meta object in a case insensitive way. I found two nice looking examples on Stack Overflow. We'll use the Array.prototype.filter method. Favor array methods over loops in JavaScript like the filter and forEach methods. I think they're much nicer to work with since there's no need to setup variables for counting loop iterations and all that stuff.
Spoiler: Source
Code:
function valueOf(object, key) {
    "use strict";

    const keys = Object.keys(object);
    const property = keys.filter(function (k) {
        return k.toLowerCase() === key.toLowerCase();
    })[0];

    return object[property];
}

Game_Actor.prototype.equipWeight = function () {
    "use strict";

    let weight = 0;
    const equips = this.armors().concat(this.weapons());

    equips.forEach(function (item) {
        const itemWeight = valueOf(item.meta, "equip weight");

        if (itemWeight !== undefined) {
            weight += Number(itemWeight);
        }
    });

    return weight;
};
Ok, I never said twice as fast, I only said 'saves time'; secondly we really are just arguing methodologies at this point, which does what and which is better for what reason

I got it to work, and I did try using meta before using what I am at the moment

I may not know all the intercity of whats going on under the hood of this engine, but I personal feel that managing the assignment of the note tags should be done where I put, if you disagree that is perfectly reasonable point of view

As for the video resource, asking for help on a specific issue and receiving an answer that is "learn how to code" (that's how I saw the video) is on hand excess information and on the other can be seen a little lazy (though neither was your intention); I agree it is better to learn how and why things work then to just say do this, but there may be better ways to do so

Also, you seem to have taken into your account of social and geographic situation but you didn't consider ones experience, sure I may not have done much with RPG Maker before, but I am no novice to programming nor JavaScript, my issues are more with interfacing with the unfamiliar engine and the fact most of my JavaScript experience has been run inside HTML so I had never come across things like console or alter since I never need such tools before

I am trying hard to not be rude here, cause I understand you are taking the time an effort to help people in their endeavours, and that is commendable, so arguing over these silly little things is annoying as it feels like am being insensitive but at the same time I need to make my point clear, so I'm sorry if I am coming across as rude or ignorant

On other side, I rewrote part of it so I don't need brackets to refer to my "variables" any more
Yeah, I think you're right. I'll cut it out. I am really surprised that you'd never come across console or the alert method. Those have been my go to for quick and dirty debugging for so long now that it's tough for me to imagine someone missing out on them. Especially alert since it's such a good hook to get people started with JS in a browser.
Yeah, I'm more use to stuff like print and c.out since I've done a lot more with Java, C++ and C#, plus running JavaScript inside HTML you end up just reading the JS variables and displaying them with HTML

Original thread: https://forums.rpgmakerweb.com/threads/equipment-weight-plugin.88819/