Go to Page... |
Thread Tools | Display Modes |
02/02/22, 01:41 PM | #1 | |
Join Date: Apr 2018
Posts: 13
|
Python to generate esoui_constants_live.lua
Howdy,
I'm playing around with the automatic generation of a file with functions that will take constant values and return the appropriate text, such as CurrencyType_get_string(0) returns "CURT_ALLIACANCE_POINTS". It's not elegant - I basically took a hammer to it. I'm having trouble using the output file atm, tho. Is there a fixed url to find the live docs? Is there a limit on .lua file sizes? Currently I'm limiting the output to just the mappings that I need and if I let it generate them all the file is around 1MB. [edit] Code is now here: https://github.com/marcjordan2112/get_esoui_api_data The current output follows. I save this to a file called esoui_constants_live.lua in my egr addon directory. What's the proper way to include the file and use the functions? Code:
local ACTIONBARSLOTTYPE_STRINGS = { [1] = "ACTION_TYPE_ABILITY", [6] = "ACTION_TYPE_CHAMPION_SKILL", [7] = "ACTION_TYPE_COLLECTIBLE", [8] = "ACTION_TYPE_EMOTE", [2] = "ACTION_TYPE_ITEM", [0] = "ACTION_TYPE_NOTHING", [10] = "ACTION_TYPE_QUEST_ITEM", [9] = "ACTION_TYPE_QUICK_CHAT", } function ActionBarSlotType_get_string(value) return ACTIONBARSLOTTYPE_STRINGS[value] or tostring(value) } Last edited by Gullyable : 02/03/22 at 06:56 PM. |
|
02/02/22, 03:08 PM | #2 |
You can find the latest file for live at this url: https://github.com/esoui/esoui/blob/...umentation.txt
It's usually updated within a few hours after a new doc file becomes available, which sometimes can take a day or so after the update goes live. As for file size limit there is no real limit (technically there is, but it's astronomically big). Bigger files have a direct impact on login time and at some point you will get kicked by the server before you can load into the game. 1MB should be fine though, considering some saved variable files are several hundreds of MB in size. Just a heads up, it looks like you are redefining the variables globally in your file. That's something you should avoid doing because it will break the game on an update in case the constants change their value. Other addons did similar things in the past and it always ends up being a huge hard to debug mess when users complain to author A about some issue and it turns out author B did something they shouldn't have done. On another note, you can simplify the code by using a lookup table like this: Lua Code:
|
|
02/02/22, 03:52 PM | #3 |
Just as a heads-up:
You could even strip the [number] indices at the table in lua if the values are non-gap numbers 1, 2, 3, 4, 5, ... n Lua Code:
I guess, as you generate the entries via python code you will just always create the indices |
|
02/02/22, 05:56 PM | #4 | ||
Join Date: Apr 2018
Posts: 13
|
Thanks for info!
I was totally thinking about changing it to a lookup table using the value as index. It's a trivial change, too. And good point on the global redefs.
|
||
02/02/22, 05:58 PM | #5 | ||
Join Date: Apr 2018
Posts: 13
|
The docs don't specify the def values so I'm just assuming they always start at zero and go up sequentially.
|
||
02/02/22, 06:38 PM | #6 |
No, not always afaik. But most do.
Some start at 1, not at 0. 0 values often have a constant ending on _NONE too, e.g. ITEM_LAUNDER_RESULT_NONE Some use -1 and an _INVALID constant like ITEM_TRAIT_TYPE_CATEGORY_INVALID And there often exist matching *_ITERATION_START and *_ITERATION_END variables then, e.g. ITEM_FUNCTIONAL_QUALITY_ITERATION_START and _END |
|
02/03/22, 03:20 AM | #7 | |
The only way to get the actual values is to create a script to dump their values into the saved variables and parse that file outside the game. |
||
02/03/22, 06:52 AM | #8 |
I got such an addon already, will attach it here for you.
You just need to change the "DumpVars_constants.lua" file, table "DumpVars.constantsToDump", with the constants each time and can use /dumpvars ingame then in the chat to dump them to teh SavedVariables file DumpVars.lua You should, before login!, delete that file so it get's re-created freshly. |
|
02/03/22, 12:26 PM | #9 | ||
Join Date: Apr 2018
Posts: 13
|
|
||
02/03/22, 12:27 PM | #10 | ||
Join Date: Apr 2018
Posts: 13
|
|
||
02/03/22, 12:42 PM | #11 | ||
Join Date: Apr 2018
Posts: 13
|
|
||
02/03/22, 12:49 PM | #12 |
I got it at github, you can link to it:
https://github.com/Baertram/ESO-Cons...mper/tree/main |
|
02/03/22, 05:13 PM | #13 | ||
Join Date: Apr 2018
Posts: 13
|
I've got it updating DumpVars savefile properly. A bit more python and I'll be there... |
||
02/03/22, 06:59 PM | #14 | ||
Join Date: Apr 2018
Posts: 13
|
Code:
local ACTIONBARSLOTTYPE_STRINGS = { [1] = "ACTION_TYPE_ABILITY", [6] = "ACTION_TYPE_CHAMPION_SKILL", [7] = "ACTION_TYPE_COLLECTIBLE", [8] = "ACTION_TYPE_EMOTE", [2] = "ACTION_TYPE_ITEM", [0] = "ACTION_TYPE_NOTHING", [10] = "ACTION_TYPE_QUEST_ITEM", [9] = "ACTION_TYPE_QUICK_CHAT", } function ActionBarSlotType_get_string(value) return ACTIONBARSLOTTYPE_STRINGS[value] or tostring(value) } |
||
02/04/22, 04:14 AM | #15 |
Files to load need to be written in the manifest txt file of your addon, hardcoded.
Just like any other lua or xml file. If the files are stored in the data subtable it would be: Code:
/data/esoui_constants_live.lua You cannot dynamically add files to your addon via lua or ESOUI. So your python script should enhance the txt file, if you want to add filenames dyanmically. And you need to call the function names from any lua file then as long as they are global and not local. You should add all that global functions and variables to 1 namespace (1 table with your unique addon's name) though so that they do not pollute the _G global table and accidently overwrite other adon's code! e.g. in your addon's 1st file (1st lua file from the top in your manifest txt file) create 1 gobal at the top: Lua Code:
In each project lua file add at the top: Lua Code:
And your functions and variables should be added to that global table then: Lua Code:
You will be able to call the funcs like this from any of your project files then: Lua Code:
Last edited by Baertram : 02/04/22 at 04:19 AM. |
|
02/04/22, 05:52 PM | #16 | ||
Join Date: Apr 2018
Posts: 13
|
Code:
esoui_constants_live.lua EsoGrinder.lua Last edited by Gullyable : 02/04/22 at 05:54 PM. |
||
02/05/22, 10:47 AM | #17 |
You did already include it via the EsoGrinder.txt file then.
It's exactly what I had described you: Your addon's txt file needs to hardcode the lua files you want to include in your addon's usage, and you did that via the line esoui_constants_live.lua If you want to call the functions from esoui_constants_live.lua now you just need to use them in your EsoGrinder.lua code e.g. via local variableName = ActionBarSlotType_get_string(ACTION_TYPE_ABILITY) |
|
02/05/22, 02:40 PM | #18 | ||
Join Date: Apr 2018
Posts: 13
|
Here's what's in my EsoGrinder.txt:
Code:
## Title: ESO Grinder ## Description: Log loot to your ESO save file and from there to a database via the EFSM Python service. ## Author: Marc Jordan ## Version: 3.0.0 ## AddOnVersion: 3.0.0 ## APIVersion: 100028 100033 100035 101032 ## SavedVariables: EsoGrinderSavedVariables ## ## This Add-on is not created by, affiliated with or sponsored by ZeniMax Media Inc. or its affiliates. ## The Elder Scrolls® and related logos are registered trademarks or trademarks of ZeniMax Media Inc. in the United States and/or other countries. ## All rights reserved ## ## You can read the full terms at https://account.elderscrollsonline.com/add-on-terms esoui_constants_live.lua EsoGrinder.lua Here are the contents of my esoui_constants_live.lua: Code:
local CURRENCYCHANGEREASON_STRINGS = { [22] = "CURRENCY_CHANGE_REASON_ABILITY_UPGRADE_PURCHASE", [26] = "CURRENCY_CHANGE_REASON_ACHIEVEMENT", [6] = "CURRENCY_CHANGE_REASON_ACTION", [11] = "CURRENCY_CHANGE_REASON_ANTIQUITY_REWARD", [8] = "CURRENCY_CHANGE_REASON_BAGSPACE", [9] = "CURRENCY_CHANGE_REASON_BANKSPACE", [42] = "CURRENCY_CHANGE_REASON_BANK_DEPOSIT", [66] = "CURRENCY_CHANGE_REASON_BANK_FEE", [43] = "CURRENCY_CHANGE_REASON_BANK_WITHDRAWAL", [12] = "CURRENCY_CHANGE_REASON_BATTLEGROUND", [57] = "CURRENCY_CHANGE_REASON_BOUNTY_CONFISCATED", [56] = "CURRENCY_CHANGE_REASON_BOUNTY_PAID_FENCE", [47] = "CURRENCY_CHANGE_REASON_BOUNTY_PAID_GUARD", [64] = "CURRENCY_CHANGE_REASON_BUYBACK", [20] = "CURRENCY_CHANGE_REASON_CASH_ON_DELIVERY", [77] = "CURRENCY_CHANGE_REASON_CHARACTER_UPGRADE", [7] = "CURRENCY_CHANGE_REASON_COMMAND", [37] = "CURRENCY_CHANGE_REASON_CONSUME_FOOD_DRINK", [38] = "CURRENCY_CHANGE_REASON_CONSUME_POTION", [5] = "CURRENCY_CHANGE_REASON_CONVERSATION", [24] = "CURRENCY_CHANGE_REASON_CRAFT", [73] = "CURRENCY_CHANGE_REASON_CROWNS_PURCHASED", [69] = "CURRENCY_CHANGE_REASON_CROWN_CRATE_DUPLICATE", [67] = "CURRENCY_CHANGE_REASON_DEATH", [16] = "CURRENCY_CHANGE_REASON_DECONSTRUCT", [75] = "CURRENCY_CHANGE_REASON_DEFENSIVE_KEEP_REWARD", [14] = "CURRENCY_CHANGE_REASON_DEPRECATED_0", [23] = "CURRENCY_CHANGE_REASON_DEPRECATED_1", [17] = "CURRENCY_CHANGE_REASON_DEPRECATED_2", [49] = "CURRENCY_CHANGE_REASON_EDIT_GUILD_HERALDRY", [28] = "CURRENCY_CHANGE_REASON_FEED_MOUNT", [51] = "CURRENCY_CHANGE_REASON_GUILD_BANK_DEPOSIT", [52] = "CURRENCY_CHANGE_REASON_GUILD_BANK_WITHDRAWAL", [58] = "CURRENCY_CHANGE_REASON_GUILD_FORWARD_CAMP", [53] = "CURRENCY_CHANGE_REASON_GUILD_STANDARD", [50] = "CURRENCY_CHANGE_REASON_GUILD_TABARD", [39] = "CURRENCY_CHANGE_REASON_HARVEST_REAGENT", [70] = "CURRENCY_CHANGE_REASON_ITEM_CONVERTED_TO_GEMS", [54] = "CURRENCY_CHANGE_REASON_JUMP_FAILURE_REFUND", [40] = "CURRENCY_CHANGE_REASON_KEEP_REPAIR", [15] = "CURRENCY_CHANGE_REASON_KEEP_UPGRADE", [13] = "CURRENCY_CHANGE_REASON_KILL", [0] = "CURRENCY_CHANGE_REASON_LOOT", [76] = "CURRENCY_CHANGE_REASON_LOOT_CURRENCY_CONTAINER", [62] = "CURRENCY_CHANGE_REASON_LOOT_STOLEN", [2] = "CURRENCY_CHANGE_REASON_MAIL", [21] = "CURRENCY_CHANGE_REASON_MEDAL", [74] = "CURRENCY_CHANGE_REASON_OFFENSIVE_KEEP_REWARD", [59] = "CURRENCY_CHANGE_REASON_PICKPOCKET", [35] = "CURRENCY_CHANGE_REASON_PLAYER_INIT", [72] = "CURRENCY_CHANGE_REASON_PURCHASED_WITH_CROWNS", [79] = "CURRENCY_CHANGE_REASON_PURCHASED_WITH_ENDEAVOR_SEALS", [71] = "CURRENCY_CHANGE_REASON_PURCHASED_WITH_GEMS", [65] = "CURRENCY_CHANGE_REASON_PVP_KILL_TRANSFER", [41] = "CURRENCY_CHANGE_REASON_PVP_RESURRECT", [4] = "CURRENCY_CHANGE_REASON_QUESTREWARD", [36] = "CURRENCY_CHANGE_REASON_RECIPE", [78] = "CURRENCY_CHANGE_REASON_RECONSTRUCTION", [34] = "CURRENCY_CHANGE_REASON_REFORGE", [46] = "CURRENCY_CHANGE_REASON_RESEARCH_TRAIT", [45] = "CURRENCY_CHANGE_REASON_RESPEC_ATTRIBUTES", [61] = "CURRENCY_CHANGE_REASON_RESPEC_CHAMPION", [55] = "CURRENCY_CHANGE_REASON_RESPEC_MORPHS", [44] = "CURRENCY_CHANGE_REASON_RESPEC_SKILLS", [27] = "CURRENCY_CHANGE_REASON_REWARD", [63] = "CURRENCY_CHANGE_REASON_SELL_STOLEN", [10] = "CURRENCY_CHANGE_REASON_SOULWEARY", [18] = "CURRENCY_CHANGE_REASON_SOUL_HEAL", [25] = "CURRENCY_CHANGE_REASON_STABLESPACE", [48] = "CURRENCY_CHANGE_REASON_STUCK", [3] = "CURRENCY_CHANGE_REASON_TRADE", [33] = "CURRENCY_CHANGE_REASON_TRADINGHOUSE_LISTING", [31] = "CURRENCY_CHANGE_REASON_TRADINGHOUSE_PURCHASE", [32] = "CURRENCY_CHANGE_REASON_TRADINGHOUSE_REFUND", [30] = "CURRENCY_CHANGE_REASON_TRAIT_REVEAL", [19] = "CURRENCY_CHANGE_REASON_TRAVEL_GRAVEYARD", [68] = "CURRENCY_CHANGE_REASON_UNKNOWN", [1] = "CURRENCY_CHANGE_REASON_VENDOR", [60] = "CURRENCY_CHANGE_REASON_VENDOR_LAUNDER", [29] = "CURRENCY_CHANGE_REASON_VENDOR_REPAIR", } function CurrencyChangeReason_get_string(value) d ( zo_strformt("CurrencyChangeReason_get_string(<<1>>)", value ) ) return CURRENCYCHANGEREASON_STRINGS[value] or tostring(value) end local CURRENCYLOCATION_STRINGS = { [3] = "CURRENCY_LOCATION_ACCOUNT", [1] = "CURRENCY_LOCATION_BANK", [0] = "CURRENCY_LOCATION_CHARACTER", [2] = "CURRENCY_LOCATION_GUILD_BANK", } function CurrencyLocation_get_string(value) d ( zo_strformt("CurrencyLocation_get_string(<<1>>)", value ) ) return CURRENCYLOCATION_STRINGS[value] or tostring(value) end local CURRENCYTYPE_STRINGS = { [2] = "CURT_ALLIANCE_POINTS", [5] = "CURT_CHAOTIC_CREATIA", [7] = "CURT_CROWNS", [6] = "CURT_CROWN_GEMS", [11] = "CURT_ENDEAVOR_SEALS", [9] = "CURT_EVENT_TICKETS", [1] = "CURT_MONEY", [0] = "CURT_NONE", [8] = "CURT_STYLE_STONES", [3] = "CURT_TELVAR_STONES", [10] = "CURT_UNDAUNTED_KEYS", [4] = "CURT_WRIT_VOUCHERS", } function CurrencyType_get_string(value) d ( zo_strformt("CurrencyType_get_string(<<1>>)", value ) ) return CURRENCYTYPE_STRINGS[value] or tostring(value) end local DYEHUECATEGORY_STRINGS = { [3] = "DYE_HUE_CATEGORY_BLUE", [5] = "DYE_HUE_CATEGORY_BROWN", [2] = "DYE_HUE_CATEGORY_GREEN", [6] = "DYE_HUE_CATEGORY_GREY", [8] = "DYE_HUE_CATEGORY_IRIDESCENT", [7] = "DYE_HUE_CATEGORY_MIXED", [4] = "DYE_HUE_CATEGORY_PURPLE", [0] = "DYE_HUE_CATEGORY_RED", [1] = "DYE_HUE_CATEGORY_YELLOW", } function DyeHueCategory_get_string(value) d ( zo_strformt("DyeHueCategory_get_string(<<1>>)", value ) ) return DYEHUECATEGORY_STRINGS[value] or tostring(value) end Code:
EVENT_MANAGER:RegisterForEvent(self.name,EVENT_CURRENCY_UPDATE,self.EventCurrencyUpdateHandler) Code:
function EsoGrinder.EventCurrencyUpdateHandler( eventCode, currencyType, currencyLocation, newAmount, oldAmount, thisReason ) local new_amount = newAmount local old_amount = oldAmount local delta_amount = new_amount - old_amount local currency_type = currencyType local currency_location = currencyLocation local reason = thisReason local use_ecl = true if use_ecl then d ( "Using esoui_constants_live.lua functions." ) currency_type = CurrencyType_get_string(currencyType) -- line 262 currency_location = CurrencyLocation_get_string(currencyLocation) reason = CurrencyChangeReason_get_string(thisReason) end z = zo_strformat ( "EGR EventCurrencyUpdateHandler eventCode=<<1>> currencyType=<<2>>=<<3>> currencyLocation=<<4>>=<<5>>", eventCode, currencyType, currency_type, currencyLocation, currency_location) z2 = zo_strformat ( "<<1>> reason=<<2>>=<<3>> newAmount=<<4>> oldAmount=<<5>> delta_amount=<<6>>", z, thisReason, reason, newAmount, oldAmount, delta_amount) d ( z2 ) end
Code:
user:/AddOns/EsoGrinder/EsoGrinder.lua:262: function expected instead of nil stack traceback: user:/AddOns/EsoGrinder/EsoGrinder.lua:262: in function 'EsoGrinder.EventCurrencyUpdateHandler' <Locals> eventCode = 589829, currencyType = 1, currencyLocation = 0, newAmount = 1507506, oldAmount = 1507515, thisReason = 1, new_amount = 1507506, old_amount = 1507515, delta_amount = -9, currency_type = 1, currency_location = 0, reason = 1, use_ecl = T </Locals> |
||
02/05/22, 03:05 PM | #19 |
What is written at line 262?
Check what line 262 says, what function is tried to use there and check if you got a typo then at one of the functions CurrencyLocation_get_string or CurrencyType_get_string or CurrencyChangeReason_get_string Edit: Just saw line 262 is CurrencyType_get_string use merTorchbug or ZGOO ingame and check if it exists via /tbug CurrencyType_get_string or /zgoo CurrencyType_get_string If it returns nil that function is not existing. Either your lua file where it was defined was not loaded or you wrote a local up in front of that function? btw, if your funcs always end on "_get_string" you could create yourself a small local function to call the functions like this: Lua Code:
And check if you really got the correct file esoui_constants_live.lua in your live/AddOns/EsoGrinder folder! Maybe provide us a complete zip file of the addon ESOGrinder including the current code and files and let us see what is wrong that way, or do you have it somewhere at github maybe? Always easier to see the total! Last edited by Baertram : 02/05/22 at 03:12 PM. |
|
02/06/22, 11:51 AM | #20 | |
Join Date: Apr 2018
Posts: 13
|
I worked way too hard on the wrong way to go about this and thanks for your patience It was time to do some major refactoring so I created the sandbox_refactor branch here:
https://github.com/marcjordan2112/eg...ndbox_refactor Run it with use_ecl == false and you get something like this: Code:
EGR eventCode=589829, currencyType=1=1, currencyLocation=0=0 reason=1=1, newAmount=1507452, oldAmount=1507461, delta_amount=-9 Code:
user:/AddOns/EsoGrinder/EsoGrinder.lua:108: function expected instead of nil stack traceback: user:/AddOns/EsoGrinder/EsoGrinder.lua:108: in function 'EsoGrinder.EventCurrencyUpdateHandler' <Locals> eventCode = 589829, currencyType = 1, currencyLocation = 0, newAmount = 1507461, oldAmount = 1507470, thisReason = 1, new_amount = 1507461, old_amount = 1507470, delta_amount = -9, currency_type = 1, currency_location = 0, reason = 1, use_ecl = T </Locals> Code:
[TBUG]No inspector for 'CurrencyType_get_string' ("nil") |
|
ESOUI » Developer Discussions » General Authoring Discussion » Python to generate esoui_constants_live.lua |
«
Previous Thread
|
Next Thread
»
|
Thread Tools | |
Display Modes | |
|
|