Adding AP to Actor

Hi all,

So with the release of MV I'm trying to get into Javascript (much like other people). I've written the below to add a new AP property to Actors and change the Level Up to add AP points. It works and logs the AP increase to the console when an actor levels up and I can call the AP value through script call. I'm just wondering if I have done this the correct way or if there is a better/best practice way to achieve the same thing. This is my first plugin so apologies if it's amateurish.

Spoiler
//=============================================================================// Baba Points On Level// by Beenbaba// Date: 10/30/2015 //============================================================================= /*: * @plugindesc Points On Level Up * @author beenbaba * * @param Points * @desc Amount of Points to add to actor on level up * @default 1 */ //============================================================================= // Declare function//============================================================================= (function() { var parameters = PluginManager.parameters('BabaPointsOnLevel'); var PointsLV = (parameters['Points']); var PointsLVNum = +PointsLV //==============================================================================// SYSTEM - Add AP as property to Game_Actor Prototype//============================================================================== Object.defineProperties(Game_Actor.prototype, { _ap: { writable: true, value: 0, configurable: true, enumerable: true } }); //===============================================================================// LEVEL UP - Add Points param to current AP on Level Up//=============================================================================== var _Game_Actor_levelUp = Game_Actor.prototype.levelUp; Game_Actor.prototype.levelUp = function() { _Game_Actor_levelUp.call(this); this._level++; this.currentClass().learnings.forEach(function(learning) { if (learning.level === this._level) { this.learnSkill(learning.skillId); } }, this); this._ap += PointsLVNum; console.log($gameActors.actor(this._actorId)._ap) }; })(); // dont touch this.
Thanks in advance
I would say, that's a good start.

There's only one tiny thing.

You have copied the entire levelUp function and added your "apUp".

That means you now have the levelUp function running twice every level up.

If you only have the last two lines in your function after your ".call", the effect would be the same 😀

Code:
var _Game_Actor_levelUp = Game_Actor.prototype.levelUp;Game_Actor.prototype.levelUp = function() {_Game_Actor_levelUp.call(this);this._ap += PointsLVNum;console.log($gameActors.actor(this._actorId)._ap)};
Ah right I see now, so much better to do it your way. Thanks very much for your help!
What I would do is have an AP total on an actor and add to that, theres $gameActors (or something similar). Also, do not forget to tie in DataManager to save and load the ap info
Hmm I added a new property to the game_actor.prototype so this should give everyone the ._ap property so it would be ($gameActors.actor(this._actorId)._ap), which seems to work. Is this not a good way? I understand what you are saying about the DataManager although there are two things I'm not sure on

a ) How I would save the ap and load it again

b ) Currently if I start a new game, get some ap, save and close, then resume the game my actors ap remains the same so is it already being saved somewhere???
Hmm I added a new property to the game_actor.prototype so this should give everyone the ._ap property so it would be ($gameActors.actor(this._actorId)._ap), which seems to work. Is this not a good way? I understand what you are saying about the DataManager although there are two things I'm not sure on

a ) How I would save the ap and load it again

b ) Currently if I start a new game, get some ap, save and close, then resume the game my actors ap remains the same so is it already being saved somewhere???
You added a property to the Game_Actor class.

How I understand the save functions in the DataManager class, every property

you add to any game object besides $gameTemp, $gameMessages, and $gameTroop

will be stored in the save data.

So you don't need to do anything else to save your aps
Ah right, thats good news. Thanks!

Original thread: https://forums.rpgmakerweb.com/threads/adding-ap-to-actor.48554/