VE_BasicModule: action.item() is not a function

Hey guys, here I am with again a problem with Victor's plugins.

This time, it's the Basic Module that is acting up when combined with Action States.

upload_2019-8-23_20-55-21.png


When getAllElements() gets called as part of the getActionStates() function in the Action States plugin, that happens.
It simply catches an exception.

Code:
VictorEngine.getAllElements = function(subject, action) {
        if (action.item().damage.elementId < 0) {
            return subject.attackElements();
        } else {
            return [action.item().damage.elementId];
        }
    };
Function in question.

And it is a function that can get called by any Victor Plugin!
Did something change between RPG Maker versions, and the plugins aren't up to date.
1. Please provide links to the plugins

2. When exactly does the error happen? On the title screen? Walking around the map?

3. How can someone recreate this error? What exact steps to produce the error?

4. What is being passed to the getAllElements function?
https://victorenginescripts.wordpress.com/rpg-maker-mv/basic-module/
https://victorenginescripts.wordpress.com/rpg-maker-mv/action-states/


This happens when someone just attacks while in battle.
I've added these to a blank project, with the same errors.

Add the plugins to a project, with the basic module above action. Then create something that can trigger a battle. I use an event for this.
Then just attack with everyone. and go.

What gets parsed in are the actor and the attack action. Action does not have an item field, nor an item() function.

When action.item() gets called, it catches an exception, saying "action.item() is not a function".
Bump.
Game_Action does have an item() function. Not in Victor's scripts, but in the base scripts (rpg_objects.js). Not sure that's what's being passed in though, but if it's not I'd expect to see a lot more people reporting it.

Is this the basic attack? Have you made any changes to it? Do you need to make any changes to it for the plugin? Does it also happen if all your actors use a skill instead of attack? Does it happen if they use an item?
I decided to test it myself in a new project: Attack, the default Fire skill, default Heal skill, and default Potion item all trigger the "action.item() is not a function" error. Further testing showed that the error is only caused by skills or items that change HP, MP, or TP; skills/items that only apply/remove (de)buffs or states function normally.
Which is weird, as changing HP, MP and TP are very integral to how RPG Maker works.

Is Victor Sant still alive somewhere? Because this is a major bug, at least in this version of RPGMaker MV.
I might test on an earlier version.


@Shaz I have not touched any of the skills in my test project. It happens on the very first attack that is executed in a battle, no matter if that is an enemy or an actor. Could this be solved by adding the Game_Action.item() function to Victor's plugin?

upload_2019-8-31_18-9-56.png

upload_2019-8-31_18-10-15.png

This is everything in the action parsed in. I dont see an item field or function anywhere.
And when mousing over .item() it says "undefined"
Good use of the debugger, if you know a little on how to use it that will make this a lot easier.

Don't have MV on me at the moment, but it doesn't look like that variable "action" is even an instance of class Game_Action. In fact, it looks like that is a plain old object of a skill from the database.

In the debugger can you go one function *earlier*, and see what is getting passed as the parameter "action"?
I've checked this:

Code:
Game_Action.prototype.getActionStatesData = function(subject, data, isSkill, item) {
        var value;
        var result = [];
        if (isSkill) {
            var itemValue = data.skill[item.id] || {};
            var typeValue = data.stype[item.stypeId] || {};
        } else {
            var itemValue = data.item[item.id]  || {};
            var typeValue = data.itype[item.itypeId] || {};
        };
        var stateValue = VictorEngine.getAllStates(subject, item).reduce(function(r, stateId) {
            value = data.action[stateId] || {};
            return r.concat(value);
        }, []);
       var elmtnValue = VictorEngine.getAllElements(subject, item).reduce(function(r, elementId) {  --this gets called, and then breaks.
            value = data.element[elementId] || {};
            return r.concat(value);
        }, []);
        return result.concat(itemValue, typeValue, stateValue, elmtnValue);
    };
in VE_ActionStates.
And here "item" is the same as in my earlier finds, namely, the Attack skill in the database.

Here we have a case of the wrong kind of item being passed in. 🙁

I could do without ActionStates, but that would make it harder to do clever things when hitting enemies with certain elements, or blood swords, or other creative things in combat.


EDIT:
By debugging even earlier, namely Victor's ExecuteDamage() override, I've found that he already parses the item attached to the Game_Action there, when he starts checking all the data.
Which means that by the time we get to the GetAllElements(), we have the database object attached to the action, instead of the action itself. And of course, database objects do not have an action.
And thus, into GetAllElements, an ITEM gets passed, but the function asks for an action.

but every instance of "this" still points to the action we began with.
I'll try changing the script to take "this" into the GetAllElements() function, to see what happens.


EDIT2:

VICTORY! passing in "this" which is the action, fixed the issue.

EDIT3:
Where do I leave this as a bugfix for everyone? I mean, we haven't heard from Victor in a long time, so I doubt he is gonna fix his plugins soon.
I've checked this:

Code:
Game_Action.prototype.getActionStatesData = function(subject, data, isSkill, item) {
        var value;
        var result = [];
        if (isSkill) {
            var itemValue = data.skill[item.id] || {};
            var typeValue = data.stype[item.stypeId] || {};
        } else {
            var itemValue = data.item[item.id]  || {};
            var typeValue = data.itype[item.itypeId] || {};
        };
        var stateValue = VictorEngine.getAllStates(subject, item).reduce(function(r, stateId) {
            value = data.action[stateId] || {};
            return r.concat(value);
        }, []);
       var elmtnValue = VictorEngine.getAllElements(subject, item).reduce(function(r, elementId) {  --this gets called, and then breaks.
            value = data.element[elementId] || {};
            return r.concat(value);
        }, []);
        return result.concat(itemValue, typeValue, stateValue, elmtnValue);
    };
in VE_ActionStates.
And here "item" is the same as in my earlier finds, namely, the Attack skill in the database.

Here we have a case of the wrong kind of item being passed in. 🙁

I could do without ActionStates, but that would make it harder to do clever things when hitting enemies with certain elements, or blood swords, or other creative things in combat.


EDIT:
By debugging even earlier, namely Victor's ExecuteDamage() override, I've found that he already parses the item attached to the Game_Action there, when he starts checking all the data.
Which means that by the time we get to the GetAllElements(), we have the database object attached to the action, instead of the action itself. And of course, database objects do not have an action.
And thus, into GetAllElements, an ITEM gets passed, but the function asks for an action.

but every instance of "this" still points to the action we began with.
I'll try changing the script to take "this" into the GetAllElements() function, to see what happens.


EDIT2:

VICTORY! passing in "this" which is the action, fixed the issue.

EDIT3:
Where do I leave this as a bugfix for everyone? I mean, we haven't heard from Victor in a long time, so I doubt he is gonna fix his plugins soon.

Hi, very good job, but a question: where i can find the bugfix? 🙂

Original thread: https://forums.rpgmakerweb.com/threads/ve_basicmodule-action-item-is-not-a-function.112476/