Thread Tools Display Modes
05-22-24, 09:26 PM   #1
myrroddin
A Pyroguard Emberseer
 
myrroddin's Avatar
AddOn Author - Click to view addons
Join Date: Oct 2008
Posts: 1,246
Issue #1: reloading UI undoes table removal

After doing some tests in retail to remove and restore table entries, I noticed that reloading my UI restores the entries, which is not intended. That should happen when the UI button is pressed, line 182 of ChatOptions.lua in Modules-Mainline\Chat.

I foresee the same issue when I port the code to Classic and Cataclysm.

I thought about table.remove, but that requires a numerical index, which I can't guarantee with my current code. When I comment out lines 182-196, the table entries do not return after being set to nil.

Any suggestions are welcome!
  Reply With Quote
05-23-24, 04:38 AM   #2
myrroddin
A Pyroguard Emberseer
 
myrroddin's Avatar
AddOn Author - Click to view addons
Join Date: Oct 2008
Posts: 1,246
More information and explanation. module.randomSingleMessages will be used to print random strings.
Code:
if #module.randomSingleMessages >= 1 then
    print(math.random(#module.randomSingleMessages[module.randomSingleMessages])
end
-- EX: "I am ressing %s" with %s replaced by a target player's name
The first option group allows the user to toggle on or off which messages to use. If toggled true, add the message to module.randomSingleMessages, and toggled false then remove the message, but keep it in the overall database.

The next option group allows the user to decide to never use a message, which removes it from both module.randomSingleMessages and the database.

The last option is an undo option to restore all deleted messages to the table and the database.

Why offer both a true/false option with a nil option? Based on feedback, some users wanted to remove all my supplied messages and exclusively use their own messages.

Last edited by myrroddin : 05-23-24 at 04:39 AM. Reason: grammar
  Reply With Quote
05-23-24, 07:37 AM   #3
SDPhantom
A Pyroguard Emberseer
 
SDPhantom's Avatar
AddOn Author - Click to view addons
Join Date: Jul 2006
Posts: 2,336
Originally Posted by myrroddin View Post
After doing some tests in retail to remove and restore table entries, I noticed that reloading my UI restores the entries, which is not intended.
/reload completely wipes the Lua state the same as a normal logout would. The only way to get anything to survive is by using SavedVariables.

Originally Posted by myrroddin View Post
I thought about table.remove, but that requires a numerical index, which I can't guarantee with my current code.
Not sure how you think table.remove() is going to solve table permanency.

Originally Posted by myrroddin View Post
Why offer both a true/false option with a nil option? Based on feedback, some users wanted to remove all my supplied messages and exclusively use their own messages.
I'd personally implement this as an array stored in SavedVariables with your preloaded messages implemented as defaults that are loaded when nothing exists yet. This will let you use GetRandomArrayEntry() to pick your message and tContains() to identify if a default message exists in the array.
__________________
WoWInterface AddOns
"All I want is a pretty girl, a decent meal, and the right to shoot lightning at fools."
-Anders (Dragon Age: Origins - Awakening)

Last edited by SDPhantom : 05-23-24 at 08:35 AM.
  Reply With Quote
05-23-24, 08:51 AM   #4
myrroddin
A Pyroguard Emberseer
 
myrroddin's Avatar
AddOn Author - Click to view addons
Join Date: Oct 2008
Posts: 1,246
I didn't know either GetRandomArrayEntry() or tContains() existed. I could use those. As for persisting through reloading the UI, I am using saved variables. db.randomSingleMessages and db.deletedSingleMessages are saved. module.randomSingleMessages is not saved, which is fine. I was asking about the db entries in the top post.

Still, I will check out those APIs or functions you mentioned.
  Reply With Quote
05-23-24, 02:21 PM   #5
SDPhantom
A Pyroguard Emberseer
 
SDPhantom's Avatar
AddOn Author - Click to view addons
Join Date: Jul 2006
Posts: 2,336
The usual suspects for a SavedVariable desyncing is either something going wrong with the loading process or a table pointer got overwritten.
You might want to compare the value in db.profile with the raw data that should be found in the global that actually contains your SavedVar.

I personally never used the Ace framework, so all I really see at a glance are just tables with various things stored in them. Not a lot of help, but perhaps a clue on where to start looking.
__________________
WoWInterface AddOns
"All I want is a pretty girl, a decent meal, and the right to shoot lightning at fools."
-Anders (Dragon Age: Origins - Awakening)

Last edited by SDPhantom : 05-23-24 at 02:26 PM.
  Reply With Quote
05-24-24, 01:51 AM   #6
myrroddin
A Pyroguard Emberseer
 
myrroddin's Avatar
AddOn Author - Click to view addons
Join Date: Oct 2008
Posts: 1,246
I found part of the problem, which is a display bug rather than a table function bug. On line 368 of Core-Mainline.lua I localize a table's keys but do not check for value type.

That means keys with nil values are being localized, which shouldn't happen, which means the output table included nil values for keys.

I am about to try this new version, renamed to reflect what the function does. From there, I will continue testing the table functions SDPhantom linked.

Old version because line number change:
Lua Code:
  1. -- translate input table and return localizations
  2. function addon:TranslateTable(inputTable)
  3.     -- check inputTable for validity
  4.     if not inputTable or type(inputTable) ~= "table" then
  5.         error(":TranslateTable, 'inputTable' table expected, got %s", 2):format(type(inputTable))
  6.     end
  7.     local outputTable = {}
  8.     for index in pairs(inputTable) do
  9.         outputTable[index] = L[index]
  10.     end
  11.     return outputTable
  12. end

New version:
Lua Code:
  1. -- translate input table and return localizations for keys
  2. function addon:LocalizeTableKeys(inputTable)
  3.     -- check inputTable for validity
  4.     if not inputTable or type(inputTable) ~= "table" then
  5.         error(("'inputTable' table expected, got type '%s'"):format(type(inputTable)), 2)
  6.     end
  7.     local outputTable = {}
  8.     for key, value in pairs(inputTable) do
  9.         if type(value) ~= "string" or type(value) ~= "boolean" or type(value) ~=  "nil" then
  10.             error(("Expected string, boolean, or nil for 'value' in key '%s', got type '%s'"):format(key, type(value)), 2)
  11.         end
  12.         if value ~= nil then
  13.             outputTable[key] = L[key]
  14.         end
  15.     end
  16.     return outputTable
  17. end

Last edited by myrroddin : 05-24-24 at 02:08 AM. Reason: compare old version to new version of the function
  Reply With Quote

WoWInterface » Developer Discussions » Lua/XML Help » Issue #1: reloading UI undoes table removal


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off