Troller0001
I've anxiously awaited your arrival!
So I've been trying to make a UI mod (which basically adds achievements to modded games; as if the base game didn't have enough already
), but it seems that I've encountered an error of which I do not know how to fix it.
So in short, basically what I have are 2 'options'/'customizations' in the UI. One that sorts a list (by name, mod name, or achieved), and one that makes some elements not show up ('show enabled mods only').
Now, in whoward's UI tutorial, what he did was add a dynamic City State List. Some City states did not show up (E.g. they were dead/not met), and they were all sorted alphabetically.
I'm trying to achieve (pun not intended) a similar thing, but yet there appears an error in the lua.log
The odd/remarkable thing is that separately, both 'customizations' work flawlessly.
What's even more remarkable, is that the error appears as many times as 'elements are hidden'.
What's EVEN MORE remarkable is that it still seems to do what it should do, despite the runtime error.
E.g. I choose 'Enabled Only' from the 'Show mods' 'customization' (which hides 1 element), and the error appears 1 time.
I choose 'None' from the 'Show Mods' 'customization' (which hides 10 elements), and the error appears 10 times.
EDIT:
Some Images that might be helpful to get an idea of how it looks like/what happens:
'Show installed mods only'
'Show all mods'
'Show Mods' customization
---
The actual error:
-----
Snippets of the code; (You may assume that variables/tables such as tAchievements or iOrderBy are correctly set and updated in other parts of the code, as they are unrelated to the current issue)
Anyhow, kudos to whoward for his excellent UI tutorials

So in short, basically what I have are 2 'options'/'customizations' in the UI. One that sorts a list (by name, mod name, or achieved), and one that makes some elements not show up ('show enabled mods only').
Now, in whoward's UI tutorial, what he did was add a dynamic City State List. Some City states did not show up (E.g. they were dead/not met), and they were all sorted alphabetically.
I'm trying to achieve (pun not intended) a similar thing, but yet there appears an error in the lua.log
The odd/remarkable thing is that separately, both 'customizations' work flawlessly.
What's even more remarkable, is that the error appears as many times as 'elements are hidden'.
What's EVEN MORE remarkable is that it still seems to do what it should do, despite the runtime error.
E.g. I choose 'Enabled Only' from the 'Show mods' 'customization' (which hides 1 element), and the error appears 1 time.
I choose 'None' from the 'Show Mods' 'customization' (which hides 10 elements), and the error appears 10 times.
EDIT:
Some Images that might be helpful to get an idea of how it looks like/what happens:
Spoiler :
Spoiler :

'Show installed mods only'
Spoiler :

'Show all mods'
Spoiler :

'Show Mods' customization
---
The actual error:
Code:
Runtime Error: C:\Users\[USER]\Documents\My Games\Sid Meier's Civilization 5\MODS\Additional Achievements (v 1)\UI/Dialog.lua:192: attempt to index field '?' (a nil value)
-----
Snippets of the code; (You may assume that variables/tables such as tAchievements or iOrderBy are correctly set and updated in other parts of the code, as they are unrelated to the current issue)
Spoiler :
Code:
function UpdateSorting(iOrderBy)
if iOrderBy == 1 then
--order by name
print("OrderBy Name detected!");
Controls.AAStack:SortChildren(SortByName);
elseif iOrderBy == 2 then
--order by achieved
print("OrderBy Achieved detected!");
--sort by name first, and then sort by achieved! (we ALWAYS want our secondary
--'ordering' as 'alphabetical A-Z', i.e. as SortByName)
Controls.AAStack:SortChildren(SortByName);
Controls.AAStack:SortChildren(SortByAchieved);
elseif iOrderBy == 3 then
--order by modName
print("OrderBy ModName detected!");
Controls.AAStack:SortChildren(SortByName);
Controls.AAStack:SortChildren(SortByModName);
else
--order by modID
print("OrderBy ModID detected!");
Controls.AAStack:SortChildren(SortByName);
Controls.AAStack:SortChildren(SortByModID);
end
end
function SortByName(a, b)
local sNameA = g_SortAchievementsTable[tostring(a)].Name --this is line 192 xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
local sNameB = g_SortAchievementsTable[tostring(b)].Name
return sNameA < sNameB
end
Code:
local g_CSManager = InstanceManager:new("AA", "AA_Box", Controls.AAStack)
local g_SortAchievementsTable;
function UpdateAA()
g_CSManager:ResetInstances()
g_SortAchievementsTable = {};
Init();
end
function Init()
for iType,bUnlocked in pairs(tAchievements) do
if iShowModsChosen == 1 or (iShowModsChosen == 3 and IsEnabled(GameInfo.Achievements[iType].ModID)) then
print(iType);
local instance = g_CSManager:GetInstance();
local iUnlocked = 0;
if IsAAUnlocked(iType) then iUnlocked = 1 end;
g_SortAchievementsTable[tostring(instance.AA_Box)] = {Name=Locale.ConvertTextKey(GameInfo.Achievements[iType].Header), ModName=Locale.ConvertTextKey(GameInfo.Achievements[iType].ModName), ModID=GameInfo.Achievements[iType].ModID, Achieved = iUnlocked}
--do some UI stuff such as setting Icons and text
end
end
--UpdateSorting(iOrderByChosen);
Controls.AAStack:SortChildren(SortByName);
Controls.AAStack:CalculateSize()
Controls.AAStack:ReprocessAnchoring()
Controls.AAPanel:CalculateInternalSize()
end
Code:
<?xml version="1.0" encoding="utf-8" ?>
<!--Special Thanks to Whoward69 for his excellent UI tutorials!-->
<Context>
<Box Style="BGBlock_ClearTopBar" />
<Instance Name="AA">
<Box ID="AA_Box" Size="550,85" Anchor="L,C" Offset="0,0" Color="White.0" >
<Image Anchor="L,T" Offset="25,0" Size="80,80" Texture="NotificationFrameBase.dds">
<Image ID="AAIcon" Anchor="L,T" Offset="0,0" Size="80,80"
Texture="NotificationGeneric.dds" />
</Image>
<Label ID="Label" Anchor="L,T" Size ="10,10" Offset="110,10" Font="TwCenMT22" FontStyle="Shadow" ColorSet="Beige_Black_Alpha">
<Label ID="LabelDesc" Anchor="L,T" Size ="10,1" LeadingOffset="-5" Offset="0,25" WrapWidth="400" Font="TwCenMT14" FontStyle="Shadow" ColorSet="Beige_Black_Alpha"/>
</Label>
</Box>
</Instance>
<Grid Size="600,400" Anchor="C,C" Style="Grid9DetailFive140" ConsumeMouse="1">
<!--Order by - Scroll list-->
<PullDown ID="AA_OrderBy" Style="GenericPullDown"
ScrollThreshold="170" Size="200,27" SpaceForScroll="1" Anchor="C,T"
Offset="-170,11">
</PullDown>
<!--Show mods - scroll list-->
<PullDown ID="AA_ShowMods" Style="GenericPullDown"
ScrollThreshold="170" Size="200,27" SpaceForScroll="1" Anchor="C,T"
Offset="30,11">
</PullDown>
<!--Achievopedia Title-->
<Label ID="AA_Title" Anchor="C,T" Offset="0,-10" Font="TwCenMT24"
FontStyle="SoftShadow" ColorSet="Beige_Black_Alpha"
String="TXT_KEY_AA_TITLE"/>
<Label ID="Message" Anchor="C,T" Offset="0,50" Font="TwCenMT24"
FontStyle="SoftShadow" ColorSet="Beige_Black_Alpha"
String="TXT_KEY_BUTTON_AA_TITLE"/>
<ScrollPanel ID="AAPanel" Anchor="C,C" Size="500,200" Vertical="1">
<Stack ID="AAStack" Anchor="C,T" StackGrowth="Bottom" Offset="0,0" Padding="5"/>
<ScrollBar Offset="0,18" Anchor="R,T" AnchorSide="O,I"
Style="VertSlider" Length="164" />
<UpButton Offset="0,0" Anchor="R,T" AnchorSide="O,I"
Style="ScrollBarUp" />
<DownButton Offset="0,1" Anchor="R,B" AnchorSide="O,I"
Style="ScrollBarDown" />
</ScrollPanel>
<GridButton ID="OK" Size="140,36" Anchor="C,B" Offset="0,50"
Style="BaseButton" ToolTip="TXT_KEY_BUTTON_AA_OK_TOOLTIP">
<Label Anchor="C,C" Offset="0,-2"
String="TXT_KEY_BUTTON_AA_OK" Font="TwCenMT24"
FontStyle="Shadow" ColorSet="Beige_Black_Alpha" />
</GridButton>
</Grid>
</Context>
Anyhow, kudos to whoward for his excellent UI tutorials

Last edited: