PDA

View Full Version : Shortcuts without using draginfo?



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.

Trenloe
September 17th, 2014, 17:18
Link controls are usually windowreferencecontrol elements: https://www.fantasygrounds.com/refdoc/windowreferencecontrol.xcp#getTargetDatabaseNode

You can add the link reference using <windowreferencecontrol >.setValue(<module reference>)

The <module reference> is the usual <name>@<module name>

As an example, the skills entry in the PFRPG ruleset has a link on the far right that accepts skills dragged from the PFRPG Basic Rules. If I drag an acrobatics skill from the library module to this link it is stored in the database as: reference.skills.acrobatics@PFRPG Basic Rules

reference.skills.acrobatics is the database reference to the record in the module.
@PFRPG Basic Rules is the module name.

So, if you were coding this in the background in the PFRPG ruleset, the windowreferencecontrol in the PFRPG for the skill link is called "shortcut" (in the PFRPG campaign\record_char_skills.xml file). So, to set the acrobatics skill module reference in this "shortcut" windowreferencecontrol use the following LUA: shortcut.setValue("reference.skills.acrobatics@PFRPG Basic Rules");

DMFirmy
September 17th, 2014, 21:06
So, if you were coding this in the background in the PFRPG ruleset, the windowreferencecontrol in the PFRPG for the skill link is called "shortcut" (in the PFRPG campaign\record_char_skills.xml file). So, to set the acrobatics skill module reference in this "shortcut" windowreferencecontrol use the following LUA: shortcut.setValue("reference.skills.acrobatics@PFRPG Basic Rules");

Thank you for the help, but now I am having a different issue with this piece of code. I modified the getCharacterSheetSkills function to add a new value to store the string for the reference, which would be the string "reference.skills.acrobatics@PFRPG Basic Rules" in your example. Then I went and added a new line to the top of the onInit() method in char_skill.lua to set the value to the reference string.

The shortcut is being created, but clicking on it gives me the following runtime error:

Runtime Error: desktop: Unable to create window with invalid class (reference.skills.acrobatics@Theon Campaign Setting Basic Rules)

There is a window class defined called referenceskill that is being used to display the skill page from the reference module. I would ideally want this same window class to be used to display the skill when the shortcut is clicked, but I cannot seem to figure out how to set the class to be used when the shortcut is clicked.

Thank you, by the way, for the prompt response and for all the help you have been providing me as I work on this project. FG is a pretty large beast under the hood, and the lack of proper debugging and visual development tools makes things a bit difficult to navigate from the start.

Trenloe
September 17th, 2014, 21:19
Sorry, I misread the definition of <windowreferencecontrol>.setValue:

https://www.fantasygrounds.com/refdoc/windowreferencecontrol.xcp#setValue

This takes two parameters, windowclass and recordname.

So, for the example record we're using, the code would be:

shortcut.setValue("referenceskill", "reference.skills.acrobatics@PFR PG Basic Rules");

So, this will open in a new window the referenceskill <windowclass> with the reference.skills.acrobatics@PFR PG Basic Rules data.

DMFirmy
September 17th, 2014, 21:25
Sorry, I misread the definition of <windowreferencecontrol>.setValue

...

shortcut.setValue("referenceskill", "reference.skills.acrobatics@PFR PG Basic Rules");

Thank you a ton, that did the trick. I guess I should have thought to go back to the ref docs and double check myself before posting, but this is super helpful for me. I appreciate it a ton!