Add array data as part of actor properties

Kilitar

Veteran
Veteran
Joined
Jul 28, 2015
Messages
141
Reaction score
41
First Language
czech
Primarily Uses
RMMV
Hello.
I am fighting with JS in MV. I made plugin with guild system.

GuildName is defined by string - (name defined by plugin parameters)

In each guild you have 12 titles you can achieve (starting from newbie to grandmaster) - you are tagged by highest one - so for Smith guild you can be apprentience smith

So - GuildTitles is array of 12 strings.

Basic object structure (prototype?) for Guild is:

Code:
  function Guild (GuildName, GuildTitles) {
            this.name = GuildName;        // name of Guild - string from plugin parametters
            this.titles = GuildTitles;          // array - set of ranks/titles within guild
            this.member = false;             //  Check if actor is already member - each actor can be member of each guild as long as he pays guild fee. He can also lost membership if act against guild
            this.reputation = 0;                // Actor reputation points for guild
            this.level= 0;                          // Actor level inside guild
            this.titleID= 0;                          // Actor title ID inside guild

// +few methods for check reputation needed for next level in guild, for set level, set title, etc..
        };
Then I made 9 guilds from Guild object - with imported GuildName and GuildTitles for each guild1-guild9

and merge all together inside array guilds.
Code:
  var guilds = [guild1, guild2, guild3, guild4, guild5, guild6, guild7, guild8, guild9];
Inside game it works (as well as methods)


First issue: As you can see object properties this.member this.reputation this.level and this.titleID are actor values for each actor for each guild. (so array of values unique for array of actor) while this.name and this.titles are strings - same for any actor.
What is right approach here? Should be this.member this.reputation this.level and this.titleID part of object guild or rather part of object actor ? Because of related methods for change values of these I am not sure.

Second issue: I was not able to include array of guilds to be part as actor properties. I am lost there. In rpg_object is prototype of actor, which is made from Game_Battler, which is made from Game_Battler_Base. There are functions for initialize, setup, init members,... I duno how and where include my array guilds. In fact, each actor needs only array (block of 9 guilds) made from this.member this.reputation this.level and this.titleID as name and titles are static strings forwarded from plugin parametters

Third issue: Changes made during play in reputation, level, etc.. are not saved while I save game. Yes, they are not part of actor which is probably reason. Possible approach is include them into actor (as they are related) or made save/load method for my guild plugin. Depends what is better approach?


Thank you for advices.
 
Last edited:

Poryg

Dark Lord of the Castle of Javascreeps
Veteran
Joined
Mar 23, 2017
Messages
4,048
Reaction score
10,278
First Language
Czech
Primarily Uses
RMMV
First of all, please edit your text. The first issue, second issue and third issue are in black colour, which makes it hard to read for those that use black theme. Choose "None" instead.

To answer your question though, you've made it too complicated for yourself.

Instead of having to create guilds, you could just edit the game actor class, for example like this:
Code:
Game_Actor.prototype.initialize = function (don't touch params) {
code, code
this._reputation = [0, 0, 0, 0, 0, 0, 0, 0, 0];
this._level = [0, 0, 0, 0, 0, 0, 0, 0, 0];
this._member = [0, 0, 0, 0, 0, 0, 0, 0, 0];
You don't even need guild name, guild titles and guild titleIds. Instead you can have functions
Code:
Game_Actor.prototype.guildTitle = function (titleId, rank) {
if (titleId == "Dabaduba") {
var ranks = [A,B,C,D,E];
}else if (titleId == "Bububu") {
var ranks = [F, G, H, I, J];
}
return ranks[rank];
}
And if ranks always have the same words, you can always use
Code:
Game_Actor.prototype.getRankTitle = function(rank) {
if (rank == 1) return "Newbie";
if (rank == 2) return "Apprentice";
if (rank == 3) return "Better than apprentice";
if (rank == 4) return "I still know more than 3, but am not good enough to be called expert";
}
And just handle everything via Game_Actor instead of guild object.

Also, about saving, it's hidden inside rpg_managers.js, it's called makeSaveContents
 
Last edited:

Kilitar

Veteran
Veteran
Joined
Jul 28, 2015
Messages
141
Reaction score
41
First Language
czech
Primarily Uses
RMMV
Text set to none. I did not know this forum has multiple themes.
Thank you, I am very new in object oriented programming.
 

Poryg

Dark Lord of the Castle of Javascreeps
Veteran
Joined
Mar 23, 2017
Messages
4,048
Reaction score
10,278
First Language
Czech
Primarily Uses
RMMV
You're welcome. Maybe you can try some object oriented languages like C or C++ :D the syntax there is a bit different, but the logical principles are the same.
 

Jonforum

Veteran
Veteran
Joined
Mar 28, 2016
Messages
1,608
Reaction score
1,405
First Language
French
Primarily Uses
RMMV
can you embed your code with the code button plz
 

Kilitar

Veteran
Veteran
Joined
Jul 28, 2015
Messages
141
Reaction score
41
First Language
czech
Primarily Uses
RMMV
Well, I was not able to make it work.
Code:
Game_Actor.prototype.initialize = function (don't touch params) {
code, code
this._reputation = [0, 0, 0, 0, 0, 0, 0, 0, 0];
this._level = [0, 0, 0, 0, 0, 0, 0, 0, 0];
this._member = [0, 0, 0, 0, 0, 0, 0, 0, 0];
Took me few hours to get it work. I was getting error message all the time
TypeError: Failed to execute 'createLinearGradient' on 'CanvasRenderingContext2D': float parameter 3 is non-finite.
- and as inexperienced "coder" I did not even know what should I look for so I tried to remove everything. As variables it works, as array it did not.


"this._level" property was reason, because status scene tried to draw my array instead of actor level. Actor already has this property and I overrided it with my array.
I think I should use some prefix for as naming convention - like I had seen this in Yanfly scripts and few more.


Anyway, great thanks, this little introduction to OOP logic opens new world of possibilities to me :]
 

Poryg

Dark Lord of the Castle of Javascreeps
Veteran
Joined
Mar 23, 2017
Messages
4,048
Reaction score
10,278
First Language
Czech
Primarily Uses
RMMV
Yes, that is always like that - if a variable is taken, use a different one. I justused the level to give you an illustration.
 

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

Latest Threads

Latest Profile Posts

Kingdom Under Fire: The Crusaders is finally being ported to PC. I loved playing that game on the original Xbox.
A friend told me to stop making nomnom or gulping noise when eating or drinking. Plot twist of my life. I thought people can't hear that!
Inside you are two wolves. They take in oxygen while getting rid of the Co2 gas in your body...
Ah wait, sorry. Lungs. Not wolves. that'd be silly. Wolves are huge. You probably couldnt even fit one wolf inside you.
Tag: hack and slash | gameplay: point and click. Me: "How tf two are related to each other?"

Forum statistics

Threads
94,407
Messages
920,731
Members
124,197
Latest member
FJS
Top