PDA

View Full Version : Need help with auto-populated text



mixologee
August 11th, 2021, 00:29
So I am trying to update the text in a label, based off of the value of a number field. Any help would be appreciated.

The code I have tied to the numberfield would be something like:



function onValueChanged()
local nMod = math.floor(getValue());

--...grab some label on my sheet...
local mylabel = getmylabelsomehow;

--...change the value of the text on the label based on nMod from array in another file...
mylabel.setValue(ability_level_itos[nMod]);
end


My array is a simple number to string which is in some_common_data_file.



ability_level_itos = {
["1"] = "somevalue",
["2"] = "somevalue",
["3"] = "somevalue",
["4"] = "somevalue",
["5"] = "somevalue",
};

superteddy57
August 11th, 2021, 00:48
What you can do is look at 3.5e or 5e to see how the ability scores changes the value of the modifier boxes as it would be the same principle of what you are approaching here. Using what you have above, I would do:


ability_level_itos = {
["1"] = "somevalue",
["2"] = "somevalue",
["3"] = "somevalue",
["4"] = "somevalue",
["5"] = "somevalue",
};

function onValueChanged()
local nMod = math.floor(getValue());

--[[Choose one--]]
--[[Setting by database--]]
DB.setValue(dbnode, "mylabel", "string", ability_level_itos[tostring(nMod)]);

--[[OR--]]
--[[Setting by control--]]
window.mylabel.setValue(ability_level_itos[tostring(nMod)]);
end


You can just simply place the lua table with the script outside of the function and call to it. This would make it local to this control. If you wanted it global, then you would need to set something up like data_common.lua that can be seen from the rulesets mentioned previously.

mixologee
August 11th, 2021, 02:39
Thanks for the reply. I'll test this out. I did reference 5e but was having some trouble back tracing the code. Will data_common.lua overwrite if I create a new one or just be additive to the existing like a form of inheritance? I'm still trying to figure out LUA syntax as most of my code has been written in versions of C or Java over the years.

Update: using the array as local is working as intended. TY!

superteddy57
August 11th, 2021, 03:18
If you declare a new data_common.lua in the your extension code, it will overwrite the one in the ruleset code