#is there a good example of setXMLTable
1 messages · Page 1 of 1 (latest)
local function buildExpansionFactionXMLData(xmlTable, Database)
local UIExpansionTable = {}
local UIFactionTable = {}
for i, expansion in ipairs(Database.expansionList) do
if expansion ~= "Decks" then
local expansionToggle = {
tag = "Toggle",
attributes = {
id = expansion,
text = expansion,
}
}
table.insert(UIExpansionTable, expansionToggle)
local expansionSetSection = {
tag = "VerticalLayout",
children = {
{
tag = "Toggle",
attributes = {
id = "set-"..expansion,
text = expansion,
}
},
{
tag = "GridLayout",
attributes = {
class = "factionGrid"
},
children = {}
}
}
}
local factionList = Database.factionsByExpansion[expansion]
for factionNo, faction in ipairs(factionList) d
local factionTable =
tag = "Toggle",
attributes = {
id = faction,
text = faction,
}
}
table.insert(expansionSetSection.children[2].children, factionTable)
end
table.insert(UIFactionTable, expansionSetSection)
end
end
xmlTable[4].children[1].children[1].children[5].children = UIExpansionTable
xmlTable[4].children[2].children[1].children[5].children[1].children = UIFactionTable
end
local function addXmlViaCode(Database)
local xmlTable = UI.getXmlTable() -- access the UIs XML table...
buildExpansionFactionXMLData(xmlTable, Database)
UI.setXmlTable(xmlTable) -- ... and then set the new table as the completed UI XML
end
perfect, thanks
this is a copy paste from my mod.
in the last function, I don't return the changes to xmlTable from the function, so i'm not sure how my xmlTable variable doesn't get all screwy. but hey, it works, so...
I think I'm doing something else wrong too because the script is doing print statements that arent in the lua anymore 🙃 time to fight tts scripting
that is odd!
saving the object and re-loading it from saved objects gets rid of the phantom print statements but I look to still be getting empty tables
...and discord is blocking any code blocks I try and put into here...
GDNerd if you use a Lua serialiser (such as the serpent library) you can write your xml in xml, and then convert the .getData() to view it in literal Lua
this saves a lot of time (and guessing)
that probably has to be the route yeah, I have it working as string concatenation
log(serpent.line(Global.UI.getXmlTable(), {sortkeys=true, comment=false}))
then you can just copy the output out of Atom's / VSCode's console and paste back into your code
I have
serpent = require("serpent")
as the first line in all my mods when building/testing
i've tried to use that a very long time ago, but it never made sense to me. what exactly does serpent do again?
turns this code:
myTable = {
a = 1,
b = { apple = 2, banana = true }
}
log(serpent.line(myTable))
into this string:
do _ = {
a = 1,
b = {
apple = 2,
banana = true
}
}
end
ignoring the do_end part, you're able to turn tables in TTS's memory, into a Lua string for use in your .ttslua files
so, its kind of like JSON.encode, but instead of just doing tables referenced by a variable, it does a whole piece of code?
I don't know how else to explain this other than how I've already explained this
all Lua code you write is really just one big string
which is then evaluated by the program
the serpent library basically does the reverse - turns evaluated code into a comparable code string (where possible)
cool
ATM I'm just using notepad++ as I'm in bed with the flu on my laptop, how would I add serpent to the project? Or do I have to link TTS to VScode to add it?