PDA

View Full Version : button_stringcycler nil error



bojjenclon
November 20th, 2019, 02:31
So I'm trying to write an extension for Numenera that involves a button_stringcycler placed in a window on the desktop. When I try to run the campaign with my extension enabled, I receive the following error:

Script Error: [string "common/scripts/button_stringcycler.lua"]:74: attempt to index local 'node' (a nil value)

I've looked at the code for button_stringcycler and it seems its having a problem retrieving the database node from the window object. Am I not able to use this widget from within the desktop_classes.xml file, or have I simply set something up wrong?

desktop_classes.xml


<?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="ct_stat_roll">
<sizelimits>
<minimum width="110" height="57" />
</sizelimits>

<noclose />
<nodrag />
<nodrop />

<script>
function onInit()
CtStatRoll.registerControl(self)
end

function onClose()
CtStatRoll.registerControl(nil)
end
</script>

<sheetdata>
<anchor_column name="columnanchor" />

<genericcontrol name="base">
<bounds>5,5,180,52</bounds>
<icon>stat_roll</icon>
</genericcontrol>

<button_stringcycler name="type">
<anchored width="70" height="20">
<top parent="columnanchor" anchor="bottom" offset="22" />
<left parent="columnanchor" anchor="left" offset="23" />
</anchored>
<parameters>
<labelsres>char_label_might|char_label_speed|char_label_intel lect</labelsres>
<values>might|speed|intellect</values>
<defaultlabel>-</defaultlabel>
</parameters>
<tooltip textres="char_tooltip_stat" />
</button_stringcycler>

<numbercontrol name="effort">
<anchored width="42" height="22">
<top parent="columnanchor" anchor="bottom" offset="22" />
<left parent="columnanchor" anchor="left" offset="103" />
</anchored>
<font>modcollector</font>
<default>0</default>
</numbercontrol>

<button_roll name="statroll">
<anchored width="42" height="22">
<top parent="columnanchor" anchor="bottom" offset="22" />
<left parent="columnanchor" anchor="left" offset="133" />
</anchored>
<script>
function action(stat, effort)
CypherStatRolls.rollSkill(stat, effort);
end

function onButtonPress(x, y)
local stat = CtStatRoll.getType()
local effort = CtStatRoll.getEffort()

if stat == nil then
return false
end

action(stat, effort)
return true
end
</script>
</button_roll>
</sheetdata>
</windowclass>
</root>

Trenloe
November 20th, 2019, 02:58
Looking at the file that raises the error (in the CoreRPG ruleset) - the error is caused by line 74, which tries to use the node variable which is set in the previous line (line 73): local node = window.getDatabaseNode();

This code (window.getDatabaseNode) is trying to get the database node that the Window is tied to - the window is the control container, which in this case is the desktop panel. Desktop panels don't have a datasource - see here: https://www.fantasygrounds.com/refdoc/panel.xcp Hence why this is failing.

You may be able to specify a <datasource> within your <windowclass> specification: https://www.fantasygrounds.com/refdoc/windowclass.xcp I don't know if this will work, I haven't tried this. EDIT: If it doesn't work, then you may have to use different controls. See here for a note regarding not using controls linked to the database in windows without a data source: https://www.fantasygrounds.com/refdoc/databasecontrol.xcp

Here's an example of a desktop panel with controls that aren't sourced on the database, it uses LUA code to store their values in the database: https://www.fantasygrounds.com/forums/showthread.php?43598-Target-DC-on-the-Desktop&p=387852&viewfull=1#post387852

bojjenclon
November 20th, 2019, 03:23
Thanks for the reply! I wasn't able to get datasource to work so I've switched to using a combobox instead, which is working fine.