EasyRPG / Player

RPG Maker 2000/2003 and EasyRPG games interpreter
https://easyrpg.org/player/
GNU General Public License v3.0
989 stars 185 forks source link

New Command 2054 - Get ID By Name #3214

Open jetrotal opened 5 months ago

jetrotal commented 5 months ago

This command allows you to store the ID of a database asset by searching for its name.

The syntax always comes in pairs. The first parameter of each pair indicates whether you are using a direct value or a variable/indirect variable, through ValueOrVariable().

Syntax (TPC):

@raw 2054,
      "",          // Name to search for: "MAP0001", "MyVar", etc.
      0, 0,        // Type of asset (0-18) -  0: Actor, 1: Skill, 2: Item, 3: Enemy, 4: Troop, 5: Terrain, 6: Attribute, 7: State, 8: Animation, 9: Tileset, 10: Switch, 11: Variable, 12: String Variable, 13: Common Event, 14: Class, 15: Battler Animation, 16: Map, 17: Map Event, 18: Party Member
      0, 5,        // Variable where the ID will be stored
      0, 1,        // Min range: "0" sets it to the start of the list of assets, any other value specifies the minimum index
      0, 100,      // Max range: "0" sets it to the end of the list of assets, any other value specifies the maximum index
      1, 1         // Usage of string variable instead of the search string, through StringOrVariable()

@Ghabry and @carstene1ns commented about hashing the data for better searching and retrieving data by name. https://github.com/greg7mdp/parallel-hashmap

image

But this may look good enough for a first version (it's fast enough with the 9999 variables limit from vanilla).

Ghabry commented 5 months ago

How do you plan to handle translatable strings? Some of them will require a search via the translated string when a translation is loaded and others are not translatable (not exposed by lcftrans).

A string translation must happen here and we actually have a problem: We rewrite all strings on load. Here the string has different meanings based on the context so is the first time where this cannot be used. 🤔

jetrotal commented 5 months ago

I forgot about those... Would be hard to have an extra entry called defaultName that only exists when dealing with a translated game?

Ghabry commented 5 months ago

There is no simple way to get the original because we really overwrite them completely.

You must translate your string and do the lookup. Have to check if we have an API already for this...

Ghabry commented 5 months ago

Yes this is solvable, just needs a few more Getters.

What is also interesting (?) is that the command can use String Vars and String Vars are only active when Maniac Patch is on.

I will encounter the same issue soon with my "Language Config" event command which allows altering the active translation and... needs string vars for the getter part :sweat_smile:

jetrotal commented 4 months ago

question: would be better to move here the code from this pr: https://github.com/EasyRPG/Player/pull/3124 ?

Seems better fitted than editing control variables. also thought about including stuff like screen size, map size and any other unavaliable data.