How do I add a new Property to a Prototype?

I want to add a Steps_Taken property to my events.


I'm using it for a complicated minigame.  I would also like to be able to automatically increment this whenever the event moves, like how it works for Players, but I'm okay with figuring that out seperately.  I really just want to have a new property for every Events Object, which gets created when the event gets created.


What's the best way of doing this?
  1. Open your rpg_objects.js with text editor
  2. Look for 'Game_Event.prototype.initialize'
  3. Add this variable inside the initialize

  4. this._steps = 0;


    Then it should be look like this,


    Game_Event.prototype.initialize = function(mapId, eventId) {
    Game_Character.prototype.initialize.call(this);
    this._mapId = mapId;
    this._eventId = eventId;
    this._steps = 0; // Your step variable
    this.locate(this.event().x, this.event().y);
    this.refresh();
    };



  5. Add this two method below the initialize


    Game_Event.prototype.steps = function() {
    return this._steps;
    };

    Game_Event.prototype.increaseSteps = function() {
    Game_Character.prototype.increaseSteps.call(this);
    this._steps++;
    };


    Use this script call to get the event's steps,

    Code:
    $gameMap.event(eventId).steps()


Thank you!  That's great!  So simple!
  1.  





  2. Game_Event.prototype.steps = function() {
    return this._steps;
    };

    Game_Event.prototype.increaseSteps = function() {
    Game_Character.prototype.increaseSteps.call(this);
    this._steps++;
    };







Quick question, Why you add Game_Character.prototype.increaseSteps.call(this); while it works without it?!!

Original thread: https://forums.rpgmakerweb.com/threads/how-do-i-add-a-new-property-to-a-prototype.64566/