PDA

View Full Version : Feats in Foundation Core



VenomousFiligree
November 21st, 2011, 21:28
I am trying to get Feats working in Foundation Core. I have copied all the files into my Barbarians of Lemuria extension and it appears to be working fine with the exception of one script error on FG startup. I don't get any further errors when creating, modifying or deleting Feats.

Script Error: [string "scripts/list_textitem.lua"]:9: attempt to call global 'getName' (a nil value)

joshuha
November 21st, 2011, 21:46
I would need to see the code in that file (as it's not part of core). Remember, I stripped out any d20 references like feats so if it is trying to reference some sort of helper feat function that function will need to be replicated in your extension.

VenomousFiligree
November 21st, 2011, 21:52
I believe I added all the templates and scripts that related to Feats and they do appear to work, I only get the error once on startup.

Was that an offer to look at the files? ;)

Here's the code for list_textitem.lua:



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

local sName;

function onInit()
sName = getName();

if gmonly and not User.isHost() then
setReadOnly(true);
end
end

function onEnter()
if not isReadOnly() and window.windowlist.addEntry then
window.windowlist.addEntry(true);
end

return true;
end

function onNavigateDown()
local winNext = window.windowlist.getNextWindow(window);
if winNext and winNext[sName] then
winNext[sName].setFocus();
winNext[sName].setCursorPosition(1);
winNext[sName].setSelectionPosition(1);
end
return winNext;
end

function onNavigateUp()
local winPrev = window.windowlist.getPrevWindow(window);
if winPrev and winPrev[sName] then
winPrev[sName].setFocus();
winPrev[sName].setCursorPosition(#winPrev[sName].getValue()+1);
winPrev[sName].setSelectionPosition(#winPrev[sName].getValue()+1);
end
return winPrev;
end

function onNavigateRight()
if tabtarget and tabtarget[1] and tabtarget[1].next and tabtarget[1].next[1] then
local target = window[tabtarget[1].next[1]];

if target and type(target) == "stringcontrol" then
target.setFocus();
target.setCursorPosition(1);
target.setSelectionPosition(1);
end
end
end

function onNavigateLeft()
if tabtarget and tabtarget[1] and tabtarget[1].prev and tabtarget[1].prev[1] then
local target = window[tabtarget[1].prev[1]];

if target and type(target) == "stringcontrol" then
target.setFocus();
target.setCursorPosition(#target.getValue()+1);
target.setSelectionPosition(#target.getValue()+1);
end
end
end

function onDeleteUp()
if isReadOnly() then
return;
end

if nodelete then
onNavigateUp();
return;
end

local win = onNavigateUp();
if not win then
win = onNavigateDown();
end

if win and getValue() == "" then
delete();
end
end

function onDeleteDown()
if isReadOnly() then
return;
end

if nodelete then
onNavigationDown();
return;
end

local win = onNavigateDown();
if not win then
win = onNavigateUp();
end

if win and getValue() == "" then
delete();
end
end

function delete()
if nodeletelast and #(window.windowlist.getWindows()) == 1 then
return;
end

local nodeWin = window.getDatabaseNode();
if nodeWin then
nodeWin.delete();
else
window.close();
end
end

function onGainFocus()
if nohighlight then
return;
end
window.setFrame("rowshade");
end

function onLoseFocus()
if nohighlight then
return;
end
window.setFrame(nil);
end

phantomwhale
November 21st, 2011, 22:48
I'm guessing that should be window.getName()

VenomousFiligree
November 21st, 2011, 22:58
I tried that, but it "broke it more". I still had the script error on FG start up, but then I also got it for each Feat on a PC sheet, when I opened the sheet.

i.e. for two feats:

Runtime Notice: Host session started
Script Error: [string "scripts/list_textitem.lua"]:9: attempt to index global 'window' (a nil value)
Script Error: [string "scripts/list_textitem.lua"]:9: attempt to call field 'getName' (a nil value)
Script Error: [string "scripts/list_textitem.lua"]:9: attempt to call field 'getName' (a nil value)

joshuha
November 21st, 2011, 23:54
Is your code for the list items being called somehow before you have created a default one or something? Windowlists can be very tricky about order the children are called/created.

VenomousFiligree
November 22nd, 2011, 07:13
Not that I'm aware of. The template (that calls the script) is in templates_common.xml and the the windowclass that uses it is in charsheet_main.xml.

VenomousFiligree
November 22nd, 2011, 18:03
If I move the script file to the ruleset it works fine, I've had similar issues here with lua files not working in an extension, but OK in a ruleset. :confused:

Zeus
November 22nd, 2011, 18:17
If I move the script file to the ruleset it works fine, I've had similar issues here with lua files not working in an extension, but OK in a ruleset. :confused:

Sounds like either you may have a conflict between objects and supporting scripts in the ruleset and those named in your extension or you have an initialisation order dependancy issue.

Try renaming the script in your extension to something different and try it again, do you get the same errors on startup?

Zeus
November 22nd, 2011, 18:22
Not that I'm aware of. The template (that calls the script) is in templates_common.xml and the the windowclass that uses it is in charsheet_main.xml.

If the template that calls the extension script is in the ruleset, that would explain why you get errors.

You also need to override the template definition in your extension as well as the script.

VenomousFiligree
November 22nd, 2011, 18:31
Everything associated with list_textitem.lua is in the extension, however if i move just the lua file to the ruleset (and leave the template etc in the extension) it goes away.

I'll try renaming now

Edit:
If I rename I get the same error, but with the newly named lua file

Zeus
November 22nd, 2011, 19:07
Is there anything else in the ruleset which is using the template? If so, you may have to also override those objects as well.

VenomousFiligree
November 22nd, 2011, 19:13
No I've search the ruleset for both the template and the script file and they're not used anywhere.

joshuha
November 22nd, 2011, 19:38
Want to send me the extension? I can look at it in the next day or two.

VenomousFiligree
November 22nd, 2011, 20:53
Want to send me the extension? I can look at it in the next day or two.
Sure, but please don't mock my "cut and paste" coding... :D
(pm me your email I should send to)

joshuha
November 23rd, 2011, 04:41
Ok, looked it over and figured out why. When you declare the global script in the extension.xml it calls the onInit function and in this case that doesn't make sense (for a list item). See here: https://www.fantasygrounds.com/refdoc/script.xcp. You still declare the script file in templates_commons.xml for the template control itself so it loads fine without it needing be to declared as a global level manager. I tested it and looks okay after you remove the 2 lines in extension.xml.

VenomousFiligree
November 23rd, 2011, 07:02
Thanks Joshuha, so you moved both scripts from extension.xml?

I always assumed scripts had to be included in extension.xml, but it sounds like as long as they are contained in ExtensionName.ext and the xml files that call then are included in extension.xml, it should work fine?