Add array data as part of actor properties

● ARCHIVED · READ-ONLY
Started by Kilitar 7 posts View original ↗
  1. 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.
  2. 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
  3. Text set to none. I did not know this forum has multiple themes.
    Thank you, I am very new in object oriented programming.
  4. 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.
  5. can you embed your code with the code button plz
  6. Well, I was not able to make it work.
    Poryg said:
    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 :]
  7. Yes, that is always like that - if a variable is taken, use a different one. I justused the level to give you an illustration.