ESOUI

ESOUI (https://www.esoui.com/forums/index.php)
-   General Authoring Discussion (https://www.esoui.com/forums/forumdisplay.php?f=174)
-   -   Function to return text for a given global? (https://www.esoui.com/forums/showthread.php?t=10042)

marcjordan 01/11/22 09:33 PM

Function to return text for a given global?
 
When you get an EVENT_CURRENCY_UPDATE callback you get a parameter called CurrencyChangeReason int value. Is there an easy way to convert that int value to the text of the global so I can debug print it?

I could do an if reason == CURRENCY_CHANGE_REASON_CASH_ON_DELIVERY and then explicitly set the text but that's kind of horrible and not resilient to global changes.

Masteroshi430 01/12/22 12:44 AM

Quote:

Originally Posted by marcjordan (Post 45180)
When you get an EVENT_CURRENCY_UPDATE callback you get a parameter called CurrencyChangeReason int value. Is there an easy way to convert that int value to the text of the global so I can debug print it?

I could do an if reason == CURRENCY_CHANGE_REASON_CASH_ON_DELIVERY and then explicitly set the text but that's kind of horrible and not resilient to global changes.

I'm interested in the answer to this too, It looks like it is a enum or maybe a table ?
*[CurrencyChangeReason|#CurrencyChangeReason]*

Baertram 01/12/22 08:30 AM

The globals like *CurrencyChangeReason can be found in the ESOUI API Documentation Pxx .txt files linked at the wiki's API version info (current live, PTS, or even older at the history) or here at the ESOUI forum topic about that current/older patch (see attachments at the forum threads):
https://wiki.esoui.com/APIVersion#live_API_version
https://www.esoui.com/forums/showthread.php?t=9923


If you search in the API documentation txt file for CurrencyChangeReason you will find this:
Code:

h5. CurrencyChangeReason
* CURRENCY_CHANGE_REASON_ABILITY_UPGRADE_PURCHASE
* CURRENCY_CHANGE_REASON_ACHIEVEMENT
* CURRENCY_CHANGE_REASON_ACTION
* CURRENCY_CHANGE_REASON_ANTIQUITY_REWARD
* CURRENCY_CHANGE_REASON_BAGSPACE
* CURRENCY_CHANGE_REASON_BANKSPACE
* CURRENCY_CHANGE_REASON_BANK_DEPOSIT
* CURRENCY_CHANGE_REASON_BANK_FEE
* CURRENCY_CHANGE_REASON_BANK_WITHDRAWAL
* CURRENCY_CHANGE_REASON_BATTLEGROUND
* CURRENCY_CHANGE_REASON_BOUNTY_CONFISCATED
* CURRENCY_CHANGE_REASON_BOUNTY_PAID_FENCE
* CURRENCY_CHANGE_REASON_BOUNTY_PAID_GUARD
* CURRENCY_CHANGE_REASON_BUYBACK
* CURRENCY_CHANGE_REASON_CASH_ON_DELIVERY
* CURRENCY_CHANGE_REASON_CHARACTER_UPGRADE
* CURRENCY_CHANGE_REASON_COMMAND
* CURRENCY_CHANGE_REASON_CONSUME_FOOD_DRINK
* CURRENCY_CHANGE_REASON_CONSUME_POTION
* CURRENCY_CHANGE_REASON_CONVERSATION
* CURRENCY_CHANGE_REASON_CRAFT
* CURRENCY_CHANGE_REASON_CROWNS_PURCHASED
* CURRENCY_CHANGE_REASON_CROWN_CRATE_DUPLICATE
* CURRENCY_CHANGE_REASON_DEATH
* CURRENCY_CHANGE_REASON_DECONSTRUCT
* CURRENCY_CHANGE_REASON_DEFENSIVE_KEEP_REWARD
* CURRENCY_CHANGE_REASON_DEPRECATED_0
* CURRENCY_CHANGE_REASON_DEPRECATED_1
* CURRENCY_CHANGE_REASON_DEPRECATED_2
* CURRENCY_CHANGE_REASON_EDIT_GUILD_HERALDRY
* CURRENCY_CHANGE_REASON_FEED_MOUNT
* CURRENCY_CHANGE_REASON_GUILD_BANK_DEPOSIT
* CURRENCY_CHANGE_REASON_GUILD_BANK_WITHDRAWAL
* CURRENCY_CHANGE_REASON_GUILD_FORWARD_CAMP
* CURRENCY_CHANGE_REASON_GUILD_STANDARD
* CURRENCY_CHANGE_REASON_GUILD_TABARD
* CURRENCY_CHANGE_REASON_HARVEST_REAGENT
* CURRENCY_CHANGE_REASON_ITEM_CONVERTED_TO_GEMS
* CURRENCY_CHANGE_REASON_JUMP_FAILURE_REFUND
* CURRENCY_CHANGE_REASON_KEEP_REPAIR
* CURRENCY_CHANGE_REASON_KEEP_UPGRADE
* CURRENCY_CHANGE_REASON_KILL
* CURRENCY_CHANGE_REASON_LOOT
* CURRENCY_CHANGE_REASON_LOOT_CURRENCY_CONTAINER
* CURRENCY_CHANGE_REASON_LOOT_STOLEN
* CURRENCY_CHANGE_REASON_MAIL
* CURRENCY_CHANGE_REASON_MEDAL
* CURRENCY_CHANGE_REASON_OFFENSIVE_KEEP_REWARD
* CURRENCY_CHANGE_REASON_PICKPOCKET
* CURRENCY_CHANGE_REASON_PLAYER_INIT
* CURRENCY_CHANGE_REASON_PURCHASED_WITH_CROWNS
* CURRENCY_CHANGE_REASON_PURCHASED_WITH_ENDEAVOR_SEALS
* CURRENCY_CHANGE_REASON_PURCHASED_WITH_GEMS
* CURRENCY_CHANGE_REASON_PVP_KILL_TRANSFER
* CURRENCY_CHANGE_REASON_PVP_RESURRECT
* CURRENCY_CHANGE_REASON_QUESTREWARD
* CURRENCY_CHANGE_REASON_RECIPE
* CURRENCY_CHANGE_REASON_RECONSTRUCTION
* CURRENCY_CHANGE_REASON_REFORGE
* CURRENCY_CHANGE_REASON_RESEARCH_TRAIT
* CURRENCY_CHANGE_REASON_RESPEC_ATTRIBUTES
* CURRENCY_CHANGE_REASON_RESPEC_CHAMPION
* CURRENCY_CHANGE_REASON_RESPEC_MORPHS
* CURRENCY_CHANGE_REASON_RESPEC_SKILLS
* CURRENCY_CHANGE_REASON_REWARD
* CURRENCY_CHANGE_REASON_SELL_STOLEN
* CURRENCY_CHANGE_REASON_SOULWEARY
* CURRENCY_CHANGE_REASON_SOUL_HEAL
* CURRENCY_CHANGE_REASON_STABLESPACE
* CURRENCY_CHANGE_REASON_STUCK
* CURRENCY_CHANGE_REASON_TRADE
* CURRENCY_CHANGE_REASON_TRADINGHOUSE_LISTING
* CURRENCY_CHANGE_REASON_TRADINGHOUSE_PURCHASE
* CURRENCY_CHANGE_REASON_TRADINGHOUSE_REFUND
* CURRENCY_CHANGE_REASON_TRAIT_REVEAL
* CURRENCY_CHANGE_REASON_TRAVEL_GRAVEYARD
* CURRENCY_CHANGE_REASON_UNKNOWN
* CURRENCY_CHANGE_REASON_VENDOR
* CURRENCY_CHANGE_REASON_VENDOR_LAUNDER
* CURRENCY_CHANGE_REASON_VENDOR_REPAIR

These globals are created as numbers e.g. in the global table _G of lua:
_G["CURRENCY_CHANGE_REASON_REFORGE"] = <number>

They should be always used instead of hardcoding the number 1, 2, 3 etc. in your addons as they might change one day. We have had that happening with a few already in the past, e.g. BAG_* constants or INVENTORY_* constants (not sure which one changed).

Unfortunately there is no way to turn the constants into there name string (constant name).
If you need this you need to build your own lookup table.
Lua Code:
  1. local myLookupTable = {
  2.   [CURRENCY_CHANGE_REASON_REFORGE] = "CURRENCY_CHANGE_REASON_REFORGE",
  3. }


You could also do a loop over the whole table _G with
for key, value in pairs(_G) do
myLookupTable[_G[key]] = key --will create a table with a global as key and the same key String as value for your lookup
end
and build that lookup tbale this way BUT you WILL be having trouble at many entries as the table _G not only stores the constants but also all other values like functions, classes etc. You'd have to sort them out by using type(value) == "number" etc., and some even raise lua error messages as they need to be looped with a special "insecure code check" function, etc.
Addons like zgoo and merTorchbug do this to show you the values in their UI.
e.g. with merTorchbug enabled you can type /tb in the chat and in the shown UI (first load will parse the whol table _G and thus it will show you how long it took to do so in the chat -> around 1-5+ seconds depening on your hardware) you can browse the constants, strings, funcitons, and other globals then.

If I'm unsure what value is what constant I use merTorchbug and open the constants tab, use the search box and type in currency_change_ and then will see the list with the name of the constant and it's value.

marcjordan 01/12/22 06:19 PM

Thanks so much for the info!

I'm going to digest this for awhile. I understand the underlying lua stuff like constants but thanks anyway for that amount of detail. I was worried that I would need to do as you suggest but hoped there was an easy API call.

What are changes to the constants tied to? ESO version?

marcjordan 01/12/22 06:23 PM

Ah, maybe I can do some preprocessing to generate a lua file that I can then import into my addon lua, pulliing in the one that matches the API version at run time.

Baertram 01/13/22 07:29 AM

Yeah, API Version in the txt file changes with major patches (dlcs, chapters) so this often incorporates constant additions/removals/changes etc.

Your txt file can use some $variables like language or api version to dynamically load filenames, this way you could load different api version dependent files automatically. Check the Wiki for the txt manifest options.

marcjordan 01/13/22 05:02 PM

Quote:

Originally Posted by Baertram (Post 45188)
Yeah, API Version in the txt file changes with major patches (dlcs, chapters) so this often incorporates constant additions/removals/changes etc.

Your txt file can use some $variables like language or api version to dynamically load filenames, this way you could load different api version dependent files automatically. Check the Wiki for the txt manifest options.

Nice. Nice.


All times are GMT -6. The time now is 03:44 AM.

vBulletin © 2024, Jelsoft Enterprises Ltd
© 2014 - 2022 MMOUI