Thread: Accessing module entries
-
September 13th, 2014, 20:58 #1
- Join Date
- Sep 2014
- Location
- Michigan
- Posts
- 65
Accessing module entries
MODERATOR: Moved into the correct forum and it's own thread specific to this question.
Here is another question I came across while I was tinkering around...
I realize that within the ruleset you can define windows and templates to display content from modules, so for example it is possible to create a custom window view for specific items (such as how the Feat entries in the 3.5E Basic Rules module are displayed in a unique window). My question is this: is it possible to refer to entries from within modules from within the ruleset itself? For example, let's suppose I create a new field for character race on the character sheet, but instead of using a text field I use some kind of selection box. Could I read in the races that are available from the open modules to populate this listbox? One of the things I am working on is a customized version of the Basic Rules module for my own campaign, and I am going to be doing quite a bit of customization compared to the 3.5E Basic Rules module. I am modifying my ruleset to display a whole bunch of custom information that I will be adding to the basic rules module, and this will include several new races. I see in the 3.5E ruleset there are some places in the Lua code where string lists are being defined, such as the long listing of available skills, that are also being detailed in the basic rules module, and it would be awesome if I could pull those values right out of the modules that are loaded instead of defining static lists in the Lua files.
In fact, I can think of several reasons that I would want to be able to reference material in a module right from the ruleset. If this is possible, I would love to see an example of this being used somewhere. Thanks in advance.Last edited by Trenloe; September 13th, 2014 at 22:01.
-
September 13th, 2014, 22:08 #2
Use DB.getRoot(<modulename>) to access the database of a module in LUA code: https://www.fantasygrounds.com/refdoc/DB.xcp#getRoot
Use Module.getModules() to return a table of the currently open modules: https://www.fantasygrounds.com/refdo...xcp#getModules
Here's some code from the Languages Extension (https://www.fantasygrounds.com/forum...G-3-0-rulesets) that combines these two API functions to search through the currently open modules to list all of the languages configured:
Code:-- List languages in modules local aModules = Module.getModules(); for _,modulename in ipairs(aModules) do --nodeLanguage = findLanguageInDB(DB.getRoot(v), sFind); for _,v in pairs(DB.getChildren(DB.getRoot(modulename), "language_extension")) do if DB.getValue(v, "languagename", "") then msg.text = "Module: " .. modulename .. ". Language = " .. DB.getValue(v, "languagename", "") .. ", font = " .. DB.getValue(v, "fontname", ""); Comm.addChatMessage(msg); end end end
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 13th, 2014, 23:27 #3
- Join Date
- Sep 2014
- Location
- Michigan
- Posts
- 65
Neat... I am going to have to try this out later tonight / tomorrow. Thanks a ton!
Thread Information
Users Browsing this Thread
There are currently 1 users browsing this thread. (0 members and 1 guests)
Bookmarks