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,938
Reaction score
1,386
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,588
Reaction score
880
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

Yesterday I made my first step towards eating more healthily.
I saw candy on discount and did not buy it.
"They yearn for what they fear for."
I always told my DA fans how much I hate slot machines. They're fine in games as a risk-and-reward system. But when you're spending REAL MONEY in a Vegas casino to try and hit the jackpot (which very, very few people will), it can really hurt your budget. Gambling is a bad habit, and I don't like wasting my money on a slim chance. Go to Vegas for the experience, not the jackpot.
Took the kids to a corn maze. They gave us a map and had lights at certain points in the maze. Not overwhelming... or underwhelming... just... whelming.
Okay, vacuuming fruit flies out of the air is surprisingly effective.

Forum statistics

Threads
104,396
Messages
1,006,082
Members
135,927
Latest member
mich
Top