Creating a New List Type/Class/etc
So I've got the need to create a couple of new sets of lists in my ruleset. I'm basing this off the Inventory lists system in CoreRPG, but am stuck due to my lack of coding knowledge.
I starting by duplicating the "<list_charinv", "<button_iedit" & "<button_iadd" sections from "record_char_inventory.xml" to "record_char_main.xml" and editing as follows (and putting them inside a frame);
Code:
<list_defenses name="defenselist"> <anchored to="defensesframe">
<top offset="40" />
<left offset="15" />
<right offset="-20" />
<bottom offset="-15" />
</anchored>
</list_defenses>
<scrollbar>
<anchored to="defenselist" />
<target>defenselist</target>
</scrollbar>
<button_iedit name="defenselist_iedit">
<anchored to="defenselist" position="aboveright" offset="5,10" />
<target>defenselist</target>
</button_iedit>
<button_iadd name="defenselist_iadd">
<anchored to="defenselist_iedit" position="lefthigh" offset="5,0" />
<target>defenselist</target>
</button_iadd>
xxx
I then duplicated the "record_char_inventory.xml" file to "record_char_defenses.xml" file and changed the windowclass name as follows;
Code:
<windowclass name="ship_defenseitem">
...
I copied "char_invlist.lua" to "ship_defenses.lua" and changed the update function to;
Code:
function update()
local bEditMode = (window.defenseslist_iedit.getValue() == 1);
window.idelete_header.setVisible(bEditMode);
for _,w in ipairs(getWindows()) do
w.idelete.setVisibility(bEditMode);
end
end
I added the includefile to base.xml;
Code:
<includefile source="campaign/record_char_defenses.xml" />
I wondered about an include for "ship_defenses.lua", but "char_invlist.lua" doesn't have one.
I added the "list_defense" windowclass template to the "template_char.xml" as follows;
Code:
<template name="list_defenses">
<windowlist>
<child></child>
<child><backcolor>1A40301E</backcolor></child>
<datasource>.defenses</datasource>
<class>ship_defenseitem</class>
<allowdelete />
<script file="campaign/scripts/ship_defenses.lua" />
</windowlist>
But now I'm getting the following error when I click the edit button to add a new defense. Maybe I need to initialize a variable or create the database field or...? Anyway, my Find in Files has failed to indicate what I'm missing :(
Quote:
Script Error: [string "campaign/scripts/ship_defenses.lua"]:72: attempt to index field 'defenseslist_iedit' (a nil value)
Help would be appreciated, as I've spent an hour plus on just this error :(