PDA

View Full Version : Would like help making new sidebar tabs



Dailyn
February 6th, 2022, 23:51
I've been trying to setup a new sidebar tab that basically functions as another 'Feats' tab. Ideally it would be as an extension since that seems the easiest to plug-and-play with different rulesets.

I've managed to get a tab with the correct name up after looking up an old thread on this topic. However, whenever I click the 'Add Item' button (Green button, bottom right of the window) I get the following error:



[ERROR] Script execution error: [string "campaign/scripts/campaign_button_new.lua"]:28: attempt to index local 'w' (a nil value)


I'll also provide two images that I hope will highlight what I'm trying to do.
Image 1
51357
The red circle over the sidebar tab (Inscriptions) creates the 'Inscriptions' window.
The blue circle over the sidebar tab (Recursions) is the extension that I was attempting to use/modify. Link to original post here: https://www.fantasygrounds.com/forums/showthread.php?49598-Help-Adding-Button-to-Sidebar

51358
Picture of the error log incase I missed something important in my highlighted code above.

Any insights would be greatly appreciated.

superteddy57
February 7th, 2022, 00:02
To add a new sidebar button
1) setup a new data_library.lua file
- I tend to setup and append the name (e.g. data_library_fallout.lua) and place it under the scripts folder. This is normal practice to keep things organized.

2) create a new lua table that I tend to name it aRecordOverrides. As I can use this to also overwrite base library records.

3) In that same file, setup an onInit function to run the override function to set new records up.

Here is an example of one setup. CoreRPG's data_library.lua breaks down all the various tags you can use to set up the table entry. For starter, it's best to look at how CoreRPG/3.5e/5e sets these up and tinker from there.
51359

4) Next I setup the strings in a strings xml file. The way it's done is with three strings and I append with the name of the record I setup in the data_library.
<string name="library_recordtype_label_recordname">recordname</string>
<string name="library_recordtype_single_recordname">recordname</string>
<string name="library_recordtype_empty_recordname">recordname</string>

5) The last bit is to setup the record itself and that changes based on what you are trying to accomplish with this record. For starters, I just setup an empty windowclass for testing at this point and then move onto the record and finish that out. Also need to declare the new files in the base.xml or extension.xml so FG knows what it's looking at. From here it should display and function.

Dailyn
February 7th, 2022, 01:04
I have tried what I understood of the instructions provided and failed. I've named the label, single and empty inscription I, II, and III respectively just to see where they end up and will rename them appropriately at a later date.

Anyways, here's what I have at the moment.

extension.xml


<?xml version="1.0" encoding="iso-8859-1"?>

<root version="3.0" release="4">
<announcement text="Sidebar Additions: Inscription" font="emotefont" icon=""/>

<properties>
<name>Sidebar Additions: Inscription v0.1</name>
<version>0.1</version>

<author>Aero_drake</author>
<description>Add 'Inscriptions' to Library Data</description>
</properties>

<base>
<includefile source="scripts/data_library_inscription.lua" />
<includefile source="strings/strings_inscription.xml" />
</base>
</root>


data_library_inscription.lua


aRecordOverrides = {
-- NEW Record Type(S)
["inscription"] = {
bExport = true,
aDataMap = { "inscription", "reference.inscription"},
sRecordDisplayClass = "reference_inscription",
},
};

function onInit()
for kRecordType,vRecordType in pairs(aRecordOverrides) do
LibraryData.overrideRecordTypeInfo(kRecordType, vRecordType);
end

registerPublicNodes();
end


string.xml


<?xml version="1.0" encoding="iso-8859-1"?>

<root>
<string name="library_recordtype_label_inscription">inscription I</string>
<string name="library_recordtype_single_recordname">inscription II</string>
<string name="library_recordtype_empty_recordname">inscription III</string>
</root>


This is the compile log:
51360

And this is what the extension file folder looks like:
51361

I also really appreciate you taking the time to help me. This has been melting my brain all day

superteddy57
February 7th, 2022, 01:09
The code provided were examples and not a complete copy/paste. You don't need the registerPublicNodes() function and still need to setup the file with the proper structure as FG expects.

damned
February 7th, 2022, 02:16
data_library_inscription.lua


function onInit()

LibraryData.aRecords["skills"] = {
bExport = true,
aDataMap = { "skills", "reference.skills" },
aDisplayIcon = { "sidebar", "sidebar_down" },
sRecordDisplayClass = "skills",
}
end


strings.xml


<?xml version="1.0" encoding="iso-8859-1"?>


<root>

<string name="library_recordtype_label_skills">Skills</string>

</root>

Trenloe
February 7th, 2022, 13:54
This is the compile log:
51360
The cause of the error is eluded to in the error message - Error loading extension XML file... scripts/data_library_inscription.lua ...

The LUA script file is not an XML file. <includefile> is used for XML files (https://fantasygroundsunity.atlassian.net/wiki/spaces/FGCP/pages/996645510/includefile). Use <script> for LUA file: https://fantasygroundsunity.atlassian.net/wiki/spaces/FGCP/pages/996645578/script

Dailyn
February 10th, 2022, 04:23
After looking into what you all have suggested, I have realized that I need to basically learn FGU programming from the bottom up rather than just copy-pasting some code and tweaking the strings like I would in the other programs I usually use to code. It is significantly more alien than I had originally expected and referencing things like strings for window titles took me until just now to mostly figure out using various tutorials, some of which are extremely out of date. I'm currently using as much as I can from Damian Humpfield (damned?) in their youtube video to try and figure out the basics. Here's the video for reference: https://www.youtube.com/watch?v=R_CulFJYs-M

With that said, I think its going to be better for me to develop a deeper understanding of FGU before I attempt this extension. Is there a relatively up to date tutorial(s) that you know of that could teach someone how to make a window and records? I'm basically trying to create a nearly exact copy of the 'feats' sidebar and all of its functionality, but for different data.

Sorry about the confusion before, and thanks for the patience and help so far!

Dailyn
February 12th, 2022, 00:57
Alright, so after looking into some tutorials and getting help from MoonWizard on the discord, I now have the sidebar button working (With label!). It opens the window for the "Archives" just like the "Feats" sidebar button does. It even attempts to allow me to create new records. However, each time I attempt to add new records it opens the console and displays the error message I had referenced in my first post:
[ERROR] Script execution error: [string "campaign/scripts/campaign_button_new.lua"]:28: attempt to index local 'w' (a nil value)

Here's what I currently have for code:

extensions.xml


<?xml version="1.0" encoding="iso-8859-1"?>

<root version="3.0" release="4">
<announcement text="5E - Tutorial" font="emotefont" icon=""/>

<properties>
<name>5E - Tutorial v0.1</name>
<version>0.1</version>

<author>Aero_drake</author>
<description>Extension tutorial</description>
</properties>

<base>
<!-- Scripts -->
<script name="Sidebar_Archives" file="scripts/data_library_archives.lua" />

<!-- Strings -->
<includefile source="strings/strings_archives.xml" /> <!-- sets up the sidebar -->
<includefile source="strings/strings_sidebar_overwrites.xml" /> <!-- sets up the sidebar -->

<!-- References -->
</base>
</root>


/campaign/record_archive.xml (Copied from record_quest and replaced all three instances of "quest" with "archive" since MoonWizard suggested using the quest record to start with)


<?xml version="1.0" encoding="iso-8859-1"?>

<!--
Please see the license.html file included with this distribution for
attribution and copyright information.
-->

<root>
<windowclass name="archive_header">
<margins control="0,0,0,2" />
<script>
function onInit()
update();
end
function update()
local bReadOnly = WindowManager.getReadOnlyState(getDatabaseNode());

name.setReadOnly(bReadOnly);
cr.setReadOnly(bReadOnly);
xp.setReadOnly(bReadOnly);
end
</script>
<sheetdata>
<link_record_header name="open">
<class>archive</class>
</link_record_header>

<anchor_record_header_right name="rightanchor" />
<icon_record_locked />
<button_record_locked />

<string_record_name name="name">
<empty textres="library_recordtype_empty_archive" />
<tabtarget next="cr" />
</string_record_name>

<label name="cr_label">
<anchored>
<top parent="name" anchor="bottom" offset="7" />
<left offset="15" />
</anchored>
<static textres="cr" />
</label>
<basicstring name="cr">
<anchored to="cr_label" position="righthigh" offset="10,0" width="20" height="20" />
<tabtarget next="exp" prev="name" />
<description textres="cr" />
</basicstring>
<basicnumber name="xp">
<anchored height="20" width="65">
<top parent="name" anchor="bottom" offset="7" />
<right offset="-5" />
</anchored>
</basicnumber>
<label>
<anchored to="xp" position="lefthigh" offset="10,0" />
<static textres="xp" />
</label>
</sheetdata>
</windowclass>
</root>


/scripts/data_library_archives.lua


aRecordOverrides = {
["archive"] = {
bExport = true,
aDataMap = { "archive", "reference.archives" },
-- sRecordDisplayClass = "archive",
},
};
function onInit()
LibraryData.overrideRecordTypes(aRecordOverrides);
end