-
September 17th, 2014, 16:49 #1
- Join Date
- Sep 2014
- Location
- Michigan
- Posts
- 65
Shortcuts without using draginfo?
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:
Code: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
-
September 17th, 2014, 17:18 #2
Link controls are usually windowreferencecontrol elements: https://www.fantasygrounds.com/refdo...etDatabaseNode
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@PFR PG Basic Rules");Private Messages: My inbox is forever filling up with PMs. Please don't send me PMs unless they are actually private/personal messages. General FG questions should be asked in the forums - don't be afraid, the FG community don't bite and you're giving everyone the chance to respond and learn!
-
September 17th, 2014, 21:06 #3
- Join Date
- Sep 2014
- Location
- Michigan
- Posts
- 65
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.
-
September 17th, 2014, 21:19 #4
Sorry, I misread the definition of <windowreferencecontrol>.setValue:
https://www.fantasygrounds.com/refdo...l.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.Private Messages: My inbox is forever filling up with PMs. Please don't send me PMs unless they are actually private/personal messages. General FG questions should be asked in the forums - don't be afraid, the FG community don't bite and you're giving everyone the chance to respond and learn!
-
September 17th, 2014, 21:25 #5
- Join Date
- Sep 2014
- Location
- Michigan
- Posts
- 65
Thread Information
Users Browsing this Thread
There are currently 1 users browsing this thread. (0 members and 1 guests)
Bookmarks