RMMV actor.note... undefined?

Unqou

Veteran
Veteran
Joined
Mar 28, 2016
Messages
37
Reaction score
5
First Language
Italian
Primarily Uses
RMMV
I am trying to define a custom (binded to char and not changable) parameter so I tried to store it into a notetag (in my case <sr X> where X is a number).

The first issue I am encountering (as the title said) is that actor.note seems undefined, and this is strange.

I tried to use a debug event with this javascript code (using a single "script" command inside event)

Code:
var x = $gameActors.actor(1)
console.log(x.note)
the console returned "undefined".
If, instead, I put x.name or x._name the console.log returned something
1) name -> returned the function body which returns _name
2) _name -> returned the actor name

but why actor.note is undefined? How to know the actor note so I can parse the notetag and customize my actor in order to calculate my custom attribute with value X for that hero?
 

caethyril

^_^
Veteran
Joined
Feb 21, 2018
Messages
1,704
Reaction score
1,148
First Language
EN
Primarily Uses
RMMV
You are checking the Game_Actor object ($gameActors), i.e. the current state of an actor this playthrough; the notetag data is stored on the database record ($dataActors). Game_Actor has a method to retrieve the corresponding database record:
JavaScript:
$gameActors.actor(1).actor()
So you can get the note text of actor 1 like this:
JavaScript:
$gameActors.actor(1).actor().note

Note that (at least in the current version) there is simple built-in parsing for notetags in the form <tag:text>. This notetag data is stored under the meta property of the database record, e.g.
JavaScript:
// Assuming there's a notetag <tag: value> on actor #1...
$gameActors.actor(1).actor().meta.tag;  // ...this returns " value"
 

bgillisp

Global Moderators
Global Mod
Joined
Jul 2, 2014
Messages
13,224
Reaction score
13,760
First Language
English
Primarily Uses
RMVXA

I've moved this thread to Learning Javascript. Please be sure to post your threads in the correct forum next time. Thank you.

 

Unqou

Veteran
Veteran
Joined
Mar 28, 2016
Messages
37
Reaction score
5
First Language
Italian
Primarily Uses
RMMV
Yeah, sorry. I sometimes post in the wrong place since it is not so obvious for me when to place in MV or JS section. Thanks for moving

@caethyril thank a lot. So my next question is about this code that is obliouvsly wrong:

Code:
(function () {
    var _game_actor_base = Game_Actor.prototype.setup
    Game_Actor.prototype.setup = function(actorId) {
        _game_actor_base(actorId)
        var data = /<\s*sr\s+(\d+)\s*>/ig.exec(this.note);
        this.my_custom_attribute = parseInt(data[1], 10)
    };
})
This code did not work. my_custom_attribute is undefined... I assume since data can't collect this.note. The general idea is that the actor.my_custom_attribute should be valid for all characters (in play or not) and usable in damage formulas. Any hint?
I mean:
1) Is GameActor the right class to customize or should I customize also some other class?
2) what should I use (in Game Actor setup) instead of this.note? something like this.actor().note?

Sorry but JS help sometimes is not so clear or complete on describing JS Classes.

PS: I didn't know about meta (as you see my current code is about regexp) I should have the least RpgMaker MV (since I use steam version - for linux)... is there any example or documentation about it and how to use it?

PS2: Linux RMMV version is reported to be 1.6.1

-----------------------------------------------------------------

Edit: I solved the issue. There were some errors in my code. This is the working code:
Code:
(function () {
    var _game_actor_base = Game_Actor.prototype.setup
    Game_Actor.prototype.setup = function(actorId) {
        _game_actor_base.call(this, actorId);
        var actor = $dataActors[actorId];
        this._customParam1 = parseInt(actor.meta.sr, 10);
        this._customParam2 = actor.meta.cz;
    };
    
    Object.defineProperties(Game_Actor.prototype, {
       // xcp1
       xcp1: { get: function() { return this._customParam1; }, configurable: false },
       // xcp2
       xcp2: { get: function() { return this._customParam2; }, configurable: true }   
    });
})();
And this is the code inside the event to print xcp1 and xcp2
Code:
var x = $gameActors.actor(1)
console.log(x.xcp1)
console.log(x.xcp2)
Now the final question related to this topic: is there a tutorial about how to define own custom damage/evasion formula using those new parameters?
 
Last edited:

caethyril

^_^
Veteran
Joined
Feb 21, 2018
Messages
1,704
Reaction score
1,148
First Language
EN
Primarily Uses
RMMV
JS uses the prototype model (slightly more flexible than classes, since prototypes are objects in their own right, more info here). Basically, if you see the prototype keyword somewhere in a method's property chain then you're defining part of a "class". The this keyword works much like in other object-oriented languages: it references the current object (rather than the class/prototype).

For working out what code does what: personally I just search the code files. It'll take some time to learn the system, but that applies to any modding, not just RMMV. :kaoswt: Note that most stuff, including all the code handling event commands (Game_Interpreter) can be found in rpg_objects.js. :kaopride:

I believe this is the main "tutorial" on the base RMMV code: Trihan's "Jump into JavaScript". If you're looking for something more like a manual, you might prefer this: https://kinoar.github.io/rmmv-doc-web/ :kaojoy:

The methods related to evasion and damage are itemEva and makeDamageValue, defined on Game_Action (rpg_objects.js). You could alias those methods like you've done for the setup method of Game_Actor~ :kaophew:
 

Unqou

Veteran
Veteran
Joined
Mar 28, 2016
Messages
37
Reaction score
5
First Language
Italian
Primarily Uses
RMMV
Thank for your links, very useful. And yeah! I usually read the engine .js files as models (although I don't know JS so well) trying to figure myself how to customize the game.

Thank for pointing to Game_Action, but probably I have to manage damage formulas instead of aliasing Game_Action methods (not sure about it).

I'm currently experimenting this formula:
Code:
a.atk * 4 * a.rrf - b.def * 2
where rrf is a multiplier custom value inside an actor (defined with Object.defineProperties, and based on the xcp1 parameter showed in the code snipped on my previous reply) . But I have this two doubts on this approach:

1) is the 'rrf' parameter actually visible / usable inside damage formula?
2) how to make the formula actually valid since (at least currently) the rrf parameter actually exists only for actors and not for enemies? Are there other battlers other than actors and enemies?

PS: itemEva default function, as I see, simply returns an evasion value, It could be a good function to alter if/when I need to apply a custom evasion modifier but probably doesn't change how the system will use evasion value... however very nice suggestion, thank!
 

caethyril

^_^
Veteran
Joined
Feb 21, 2018
Messages
1,704
Reaction score
1,148
First Language
EN
Primarily Uses
RMMV
Thank for pointing to Game_Action, but probably I have to manage damage formulas instead of aliasing Game_Action methods (not sure about it).
An action is performed when a battler uses a skill or item. Evaluating the damage formula (if there is one) is part of that... :kaoswt:

The formula must have something to do with makeDamageValue, right? So let's have a look at that method in the code (rpg_objects.js); here's the first three lines:
JavaScript:
Game_Action.prototype.makeDamageValue = function(target, critical) {
    var item = this.item();
    var baseValue = this.evalDamageFormula(target);
OK, that sounds promising! Let's have a look at the evalDamageFormula method:
JavaScript:
Game_Action.prototype.evalDamageFormula = function(target) {
    try {
        var item = this.item();
        var a = this.subject();
        var b = target;
        var v = $gameVariables._data;
        var sign = ([3, 4].contains(item.damage.type) ? -1 : 1);
        var value = Math.max(eval(item.damage.formula), 0) * sign;
		if (isNaN(value)) value = 0;
		return value;
    } catch (e) {
        return 0;
    }
};
Here we see that the damage formula (a string, i.e. text) is evaluated using eval, i.e. "string to code". Several local variables are defined immediately beforehand, so that certain things can be written more concisely in the formula, e.g. b = target.

I'm currently experimenting this formula:
Code:
a.atk * 4 * a.rrf - b.def * 2
where rrf is a multiplier custom value inside an actor (defined with Object.defineProperties, and based on the xcp1 parameter showed in the code snipped on my previous reply) . But I have this two doubts on this approach:

1) is the 'rrf' parameter actually visible / usable inside damage formula?
2) how to make the formula actually valid since (at least currently) the rrf parameter actually exists only for actors and not for enemies? Are there other battlers other than actors and enemies?
  1. The objects a and b will still have all their properties. If the rrf property is defined on the skill user, a, then yes: a.rrf will be defined. :)

  2. Like you say, generally speaking this might be a Game_Enemy (or possibly something else if you're using plugins that add other battler types). If you've only defined the rrf property on Game_Actor, then you'll get unexpected behaviour if a is actually an enemy. That's one reason that the existing parameters are defined on Game_BattlerBase instead, since both actors and enemies inherit from it via Game_Battler. For reference, you can find the Game_BattlerBase stuff at around line 2125 in rpg_objects.js~
PS: itemEva default function, as I see, simply returns an evasion value, It could be a good function to alter if/when I need to apply a custom evasion modifier but probably doesn't change how the system will use evasion value... however very nice suggestion, thank!
Oh, good point! For applying the hit/evasion values, check Game_Action.prototype.apply. If you want to edit something in the middle of a method, generally that requires a complete override, i.e. copy + paste the method into your plugin then change whatever you want changed.

Note: if you just want the result, Yanfly has a Hit Accuracy plugin that lets you adjust the hit/eva stuff. Looks like it's a paid plugin now, but at least it's cheap. :p
 

Unqou

Veteran
Veteran
Joined
Mar 28, 2016
Messages
37
Reaction score
5
First Language
Italian
Primarily Uses
RMMV
Yeah I know Yanfly existence, even when it was free (and never downloaded it -.-). The reason I never used Yanfly is that it seems to me too huge (it is also hard to figure what should you need or not) and moreover it could lead me into compatibility problem if I had to add JS code without completely knowing what it is inside Yanfly itself.

So I am a person who tries to do less things, but himself (which could be annoying for you all guys because soon or later I will come here on asking questions xD) to have a better control / knowledge about what I am doing... perhaps because my main concern is more trying to develop small things than actually developing an entire game. Probably one day I will end to use Yanflys, but first I should understand how it works and what components I should download/install in what order.

Yeah... I know that there is BattlerBase... the problem is that rrf has more meaning in Actors than Enemies. I was thinking about Implementing rrf both in BattlerBase and Game_Actor using Object.defineProperties... hoping that double definition (both in BattlerBase and GameActor) could work similar like in c++ virtual inheritance (default function is BattlerBase, the GameActor function will used instead if entity is an actor replacing the Base rrf function) but I am unsure about it.

If it works that way an idea could be providing a fixed return value (1) on BattlerBase

-----

thank for focusing on Game_Action.prototype.apply. You have a deep knowldege about all class functions I see... you are great :) I often feel a bit disorientend when reading JS core files and trying to understand what part I should actually change.
 
Last edited:

caethyril

^_^
Veteran
Joined
Feb 21, 2018
Messages
1,704
Reaction score
1,148
First Language
EN
Primarily Uses
RMMV
I was thinking about Implementing rrf both in BattlerBase and Game_Actor using Object.defineProperties... hoping that double definition (both in BattlerBase and GameActor) could work similar like in c++ virtual inheritance (default function is BattlerBase, the GameActor function will used instead if entity is an actor replacing the Base rrf function) but I am unsure about it.
Yep, that should work. New definitions of existing properties replace the existing ones, just like making overrides for existing methods~ :kaojoy:

I often feel a bit disorientend when reading JS core files and trying to understand what part I should actually change.
That's totally normal! I've been helping out (and learning both JavaScript and how RMMV's code is organised) for years now, it's just a matter of practice. :kaopride:
 

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

Latest Threads

Latest Profile Posts

Who knew a adding menu commands would be so hard for something that should be a basic feature.
When you discover great tileset resources that you completely forgot that you had. :kaomad3::kaopride:
Just got a better look at the MZ RTP. I'm very happy with it, especially the sci-fi tiles and sprites. Glad I pre-ordered.
I've just checked the VisuStella Plugins for MZ and there are already 11 plugins. The Yanfly team(perhaps a big one?) really works so effectively and efficiently that some MZ users can likely use tons of Yanfly plugins right after MZ's released (still 13 days from now). I wonder if any other plugin developer(or team) will try to compete with Yanfly this time, no matter how slim the chance to win is :)
Hello! :kaopride:I am new to RPG Maker, though I have been lurking the forums for a while. :kaoswt: Hope to make some friends and learn some stuff here! :kaothx:

Forum statistics

Threads
100,597
Messages
977,608
Members
132,202
Latest member
gerreh
Top