Explain me DefineProperties

nio kasgami

VampCat
Veteran
Joined
May 21, 2013
Messages
8,949
Reaction score
3,042
First Language
French
Primarily Uses
RMMV
Hey guys! 

I wanted to work on something special for a game and I was curious because I create a base for my game but I was unsure the use of DefineProperties ....I know it's meant to short the job?

so in simple of what I saw in Game_BattlerBase ...it's seem usefull for define's a lots of states properties.

SO I want to know...how do you use these code? do I  have to use this._something 

or I could just do "something"?

here the code I have for the moment.

// Ho My Maid! Basefunction HMM_Base(){this.initialize.apply(this,arguments);} HMM_Base.prototype.constructor = HMM_Base;Object.defineProperties(HMM_Base.prototype, {// Define maid strenght. strengh: { get: function() { return this._strengh; }, configurable: true },// Define maid speed. speed: { get: function(){return this._speed; }, configurable: true },// Define }); HMM_Base.prototype.initialize = function() { this.clear(); }; HMM_Base.prototype.clear = function() { this._honor = 0; this._strengh = 0; this._hunger = 0; this._energy = 0; this._courage = 0; this._speed = 0; this._dexterity = 0; };I would like if you people can explain me how to properly use defineProperties thanks :)
 

??????

Diabolical Codemaster
Veteran
Joined
May 11, 2012
Messages
6,517
Reaction score
3,221
First Language
Binary
Primarily Uses
RMMZ
its similar to rubies attr_accessor methods, if that helps :)
 

nio kasgami

VampCat
Veteran
Joined
May 21, 2013
Messages
8,949
Reaction score
3,042
First Language
French
Primarily Uses
RMMV
I can see why although it's not really explain me how to use them properly :c

I mean after I define them how I am supposed to use them?
 

??????

Diabolical Codemaster
Veteran
Joined
May 11, 2012
Messages
6,517
Reaction score
3,221
First Language
Binary
Primarily Uses
RMMZ
function MyEpicObject(){this.initialize.apply(this,arguments);}MyEpicObject.prototype.constructor = MyEpicObject;Object.defineProperties(MyEpicObject.prototype, { attr1: { get: function(){ return this._somePrivateAttribute1; }, configurable: true }, attr2: { get: function(){ return this._somePrivateAttribute2; }, configurable: true },});var myEpicObject = new MyEpicObject();myEpicObject.attr1myEpicObject.attr2Helpful? :)
 
Last edited by a moderator:

nio kasgami

VampCat
Veteran
Joined
May 21, 2013
Messages
8,949
Reaction score
3,042
First Language
French
Primarily Uses
RMMV
I see! so now example how I use them INSIDE the current classes it's define? (myEpicObject)
 

??????

Diabolical Codemaster
Veteran
Joined
May 11, 2012
Messages
6,517
Reaction score
3,221
First Language
Binary
Primarily Uses
RMMZ
Well, you just have to have access to the object like you would any other object. The only difference between calling a 'property' and a function, is for properties, you don't need the () at the end of its name. You still have to have any scope access to the object you would normally have. :)
 

nio kasgami

VampCat
Veteran
Joined
May 21, 2013
Messages
8,949
Reaction score
3,042
First Language
French
Primarily Uses
RMMV
so I inside the defined classes I can still use 

attr1 = something

or I have to use 

this._privatevalue = something

 

??????

Diabolical Codemaster
Veteran
Joined
May 11, 2012
Messages
6,517
Reaction score
3,221
First Language
Binary
Primarily Uses
RMMZ
Using inside the class, you should always access it via 'this._privatevalue'. If you wanted your class to be able to change the value from outside the class, you would include a 'set' property value as well as a 'get', and then you define the setter function. :)

Actually, not really.. You could argue that it would be best to always call the attr1 from within the object, cayuse then it reduces the amount of lines you need to change, if you wanted to change the name of the private variable or something. :) )
 
Last edited by a moderator:

nio kasgami

VampCat
Veteran
Joined
May 21, 2013
Messages
8,949
Reaction score
3,042
First Language
French
Primarily Uses
RMMV
I see....I guess I get the idea lol...

EDIT : actually........No I just don't get it..how to use it sorry :/
 
Last edited by a moderator:

??????

Diabolical Codemaster
Veteran
Joined
May 11, 2012
Messages
6,517
Reaction score
3,221
First Language
Binary
Primarily Uses
RMMZ
Object.defineProperties(MyEpicObject.prototype, { attr1: { // GET function get: function getFunk(){ return this._somePrivateAttribute1; }, // SET function set: function setFunk(i){return this._somePrivateAttribute1 = i; }, configurable: true },});Pretty easy really, you just have to manually define both the getter and setter funciton, like, in ruby, it would look like this...

def attribute return @attributeenddef attribute=(newValue) return @attribute = newValueendOr, the much quicker ruby version of the exact same code...

attr_accessor :attributeIts all the same :)
 

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

Latest Threads

Latest Posts

Latest Profile Posts

Just beat the last of us 2 last night and starting jedi: fallen order right now, both use unreal engine & when I say i knew 80% of jedi's buttons right away because they were the same buttons as TLOU2 its ridiculous, even the same narrow hallway crawl and barely-made-it jump they do. Unreal Engine is just big budget RPG Maker the way they make games nearly identical at its core lol.
Can someone recommend some fun story-heavy RPGs to me? Coming up with good gameplay is a nightmare! I was thinking of making some gameplay platforming-based, but that doesn't work well in RPG form*. I also was thinking of removing battles, but that would be too much like OneShot. I don't even know how to make good puzzles!
one bad plugin combo later and one of my followers is moonwalking off the screen on his own... I didn't even more yet on the new map lol.
time for a new avatar :)

Forum statistics

Threads
106,017
Messages
1,018,356
Members
137,802
Latest member
rencarbali
Top