RMMV Short javascript question dealing with Actor Names

Beachsidey0

Villager
Member
Joined
Jun 3, 2020
Messages
15
Reaction score
2
First Language
English
Primarily Uses
RMMV
I have a bit of code here where to turn on a certain function I type for the Plugin Command

WeightSystemOn Actor
This lets me change the TP of the actor with other plugin commands. I then get the error which is TypeError: Cannot property 'IsActor' of null the line is in the else portion if (actor.isActor()) { which refers the line in the second code if (command === 'WeightSystemOn') this.switchWeightSystem(true, args); I believe I am getting the error because the Actors name has spacing its Celina Smokes any help would be great. Would I be able to set it to go by Actor ID instead of the name?

Code:
 Game_Interpreter.prototype.switchWeightSystem = function (flag, args) {
         var actorName = args[0];
        var actorId = 0;
        if (actorName === 'player')
            actorId = $gameParty.leader().actorId();
        else
            actorId = WeightManager.findActorIdByName(actorName);
        var actor = $gameActors.actor(actorId);
        if (actor.isActor()) {
            if (flag) actor.weightSystemOn();
            else actor.weightSystemOff();
        }
    }
Code:
var _Game_Interpreter_pluginCommand = Game_Interpreter.prototype.pluginCommand;
    Game_Interpreter.prototype.pluginCommand = function(command, args) {
        _Game_Interpreter_pluginCommand.call(this, command, args);
        if (command === 'SetWeight') this.setWeight(args);
        if (command === 'SetWeightType') this.setWeightType(args);
        if (command === 'WeightSystemOn') this.switchWeightSystem(true, args);
        if (command === 'WeightSystemOff') this.switchWeightSystem(false, args);
    };
 
Last edited:

caethyril

^_^
Veteran
Joined
Feb 21, 2018
Messages
1,922
Reaction score
1,366
First Language
EN
Primarily Uses
RMMZ
Uh...what's the error message? Something like "cannot reference property weightSystemOff of undefined", I'm guessing? :kaoswt2:

Note that you can use [code]code[/code] tags on these boards to format code nicely~
JavaScript:
Game_Interpreter.prototype.switchWeightSystem = function (flag, args) {
  var actorName = args[0];
  var actorId = 0;
  if (actorName === 'player') actorId = $gameParty.leader().actorId();
  else actorId = WeightManager.findActorIdByName(actorName);
  var actor = $gameActors.actor(actorId);
  console.log(actor);  // <- added for testing!
  if (actor.isActor()) {
    if (flag) actor.weightSystemOn();
    else actor.weightSystemOff();
  }
};
Here I've added a console output to help you check the value of your actor variable (F8 during playtest to open the console). Most of the code here looks OK so here's a couple of guesses:
  • The WeightManager.findActorIdByName function may be undefined, lacking a return statement, and/or not producing the expected output.
  • The switchWeightSystem method may be being given the wrong arguments.
 

Beachsidey0

Villager
Member
Joined
Jun 3, 2020
Messages
15
Reaction score
2
First Language
English
Primarily Uses
RMMV
I think I figured it out it was due to my Actor having a space in her name I changed it just to Celina and it works fine now.
 

ShadowDragon

Veteran
Veteran
Joined
Oct 8, 2018
Messages
2,577
Reaction score
875
First Language
Dutch
Primarily Uses
RMMV
you can use spaces in the name, but you need to tell the script
in case it contain spaces, it read it with (/\s*\more codes\s*) it depends on the code.
\s* = space or if it includes spaces, but I got someone that helped me with some
codes and this.
 

Users Who Are Viewing This Thread (Users: 0, Guests: 1)

Latest Threads

Latest Posts

Latest Profile Posts

Anyone can recommend a good gaming mouse? My mouse wheel has given up. Last mouse was steel series diablo iii edition (I know, it's been a while)
And then I figured out a way to doing a "regular animation" that's affected by PIXI particles. So now each frame of the animation gets particle effects. Soon my dreams of a world without QSprite will be realized. :kaopride:
Currently every NPC in my RPG gets a name, its kinda useless to name all, but Its also cool, somehow.
Biggest prob is to come up with different names. xD
I'm back from my visit to my family. Was really great to see them again after a year even if I had to get tested for covid for the visit.
Procrastination at it's finest.

Forum statistics

Threads
104,266
Messages
1,005,088
Members
135,780
Latest member
allmee
Top