DMFirmy
September 17th, 2014, 16:49
Hey all, I have come across another thing that I have been having a hard time figuring out on my own or finding any info about here on the forums, so I figured I'd post a quick question about it.
I am wondering how I would go about creating a shortcut to a module record in Lua without it being done as part of a drag-drop operation. I am working on a customized character sheet for my ruleset that will be inspecting all of the modules that are currently loaded to gather data, and this question arose specifically while I was working on the skills tab of the character sheet.
My ruleset is a heavily modified copy of the 3.5E ruleset, and though I am making many customizations the core parts of the original ruleset are still in place. In the 3.5E ruleset, the list of skills that is displayed on the character sheet is stored in the scripts/data_common.lua file as a static table variable called skilldata. This table defines all the default skills that get displayed on the character sheet, along with some relevant information on each skill such as its associated stat, whether it is usable untrained, etc. Most (if not all) of this information is also available in the 3.5E Basic Rules module under the Skills section. I have put together the following function to read through each loaded module (note I have changed the default formatting) to create this array dynamically:
function getCharacterSheetSkills()
local returnValue = {};
local aModules = Module.getModules();
for _, modulename in ipairs(aModules) do
if(Module.getModuleInfo(modulename).loaded) then
reference = DB.getRoot(modulename).getChild("reference");
if(reference ~= nil) then
skills = reference.getChild("skills");
if(skills ~= nill) then
skillTable = skills.getChildren();
for _, skill in pairs(skillTable) do
name = skill.getChild("name");
if(name ~= nil) then
name = name.getValue();
end
ability = skill.getChild("ability");
if(ability ~= nil) then
ability = ability.getValue();
end
checkpenalty = skill.getChild("armorcheckpenalty");
if(checkpenalty ~= nil) then
checkpenalty = checkpenalty.getValue();
end
trained = skill.getChild("trainedonly");
if(trained ~= nil) then
trained = trained.getValue();
end
sublabel = skill.getChild("sublabeling");
if(sublabel ~= nil) then
sublabel = sublabel.getValue();
end
if(name ~= nil) then
returnValue[name] = {}
if (ability ~= nil) then
returnValue[name].stat = ability
end
if (checkpenalty ~= nil) then
returnValue[name].armorcheckmultiplier = tonumber(checkpenalty)
end
if (trained ~= nil) then
returnValue[name].trainedonly = trained
end
if (sublabel ~= nil) then
returnValue[name].sublabeling = sublabel
end
end
end
end
end
end
end
table.sort(returnValue);
return returnValue;
end
I have done a little bit of testing, and this works perfectly for creating the skill list and loading it into the character sheet. However, on the character sheet there is a slot for a shortcut to the skill's information. I would like to be able to modify the above function (or if necessary to create a second function for the purpose) to go through and create the shortcuts to the appropriate skill entry in the appropriate module. Any help would be greatly appreciated, since this type of functionality is something I want to make great use of in my customized ruleset. Thanks in advance.
I am wondering how I would go about creating a shortcut to a module record in Lua without it being done as part of a drag-drop operation. I am working on a customized character sheet for my ruleset that will be inspecting all of the modules that are currently loaded to gather data, and this question arose specifically while I was working on the skills tab of the character sheet.
My ruleset is a heavily modified copy of the 3.5E ruleset, and though I am making many customizations the core parts of the original ruleset are still in place. In the 3.5E ruleset, the list of skills that is displayed on the character sheet is stored in the scripts/data_common.lua file as a static table variable called skilldata. This table defines all the default skills that get displayed on the character sheet, along with some relevant information on each skill such as its associated stat, whether it is usable untrained, etc. Most (if not all) of this information is also available in the 3.5E Basic Rules module under the Skills section. I have put together the following function to read through each loaded module (note I have changed the default formatting) to create this array dynamically:
function getCharacterSheetSkills()
local returnValue = {};
local aModules = Module.getModules();
for _, modulename in ipairs(aModules) do
if(Module.getModuleInfo(modulename).loaded) then
reference = DB.getRoot(modulename).getChild("reference");
if(reference ~= nil) then
skills = reference.getChild("skills");
if(skills ~= nill) then
skillTable = skills.getChildren();
for _, skill in pairs(skillTable) do
name = skill.getChild("name");
if(name ~= nil) then
name = name.getValue();
end
ability = skill.getChild("ability");
if(ability ~= nil) then
ability = ability.getValue();
end
checkpenalty = skill.getChild("armorcheckpenalty");
if(checkpenalty ~= nil) then
checkpenalty = checkpenalty.getValue();
end
trained = skill.getChild("trainedonly");
if(trained ~= nil) then
trained = trained.getValue();
end
sublabel = skill.getChild("sublabeling");
if(sublabel ~= nil) then
sublabel = sublabel.getValue();
end
if(name ~= nil) then
returnValue[name] = {}
if (ability ~= nil) then
returnValue[name].stat = ability
end
if (checkpenalty ~= nil) then
returnValue[name].armorcheckmultiplier = tonumber(checkpenalty)
end
if (trained ~= nil) then
returnValue[name].trainedonly = trained
end
if (sublabel ~= nil) then
returnValue[name].sublabeling = sublabel
end
end
end
end
end
end
end
table.sort(returnValue);
return returnValue;
end
I have done a little bit of testing, and this works perfectly for creating the skill list and loading it into the character sheet. However, on the character sheet there is a slot for a shortcut to the skill's information. I would like to be able to modify the above function (or if necessary to create a second function for the purpose) to go through and create the shortcuts to the appropriate skill entry in the appropriate module. Any help would be greatly appreciated, since this type of functionality is something I want to make great use of in my customized ruleset. Thanks in advance.