How do I add a new Property to a Prototype?

Internetomancer

Veteran
Veteran
Joined
Nov 16, 2015
Messages
57
Reaction score
26
First Language
English
Primarily Uses
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?
 

Kadafi

Reader
Veteran
Joined
Apr 7, 2014
Messages
38
Reaction score
25
First Language
Indonesian
Primarily Uses
RMMV
  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()

 

Internetomancer

Veteran
Veteran
Joined
Nov 16, 2015
Messages
57
Reaction score
26
First Language
English
Primarily Uses
Thank you!  That's great!  So simple!
 

mrcopra

Veteran
Veteran
Joined
Jul 21, 2015
Messages
452
Reaction score
158
First Language
Not English
Primarily Uses
N/A
  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?!!
 

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

Latest Threads

Latest Posts

Latest Profile Posts

People3_5 and People3_8 added!

so hopefully tomorrow i get to go home from the hospital i've been here for 5 days already and it's driving me mad. I miss my family like crazy but at least I get to use my own toiletries and my own clothes. My mom is coming to visit soon i can't wait to see her cause i miss her the most. :kaojoy:
Couple hours of work. Might use in my game as a secret find or something. Not sure. Fancy though no? :D
Holy stink, where have I been? Well, I started my temporary job this week. So less time to spend on game design... :(
Cartoonier cloud cover that better fits the art style, as well as (slightly) improved blending/fading... fading clouds when there are larger patterns is still somewhat abrupt for some reason.

Forum statistics

Threads
105,868
Messages
1,017,085
Members
137,584
Latest member
Faustus2501
Top