PDA

View Full Version : Help me read this error message:



nezzir
May 4th, 2007, 23:05
Script Error: [string "reference_spelllistitem:link"[:1: attempt to indext a nil value

Here is the relevant code it refers to (I think):



<windowreferencefield name="link">
<bounds>5,0,20,20</bounds>
<icon>
<normal>button_openwindow</normal>
<pressed>button_emptytarget</pressed>
</icon>
<script>
function onDrag(button, x, y, draginfo)
draginfo.setType("spelldescwithlevel");
draginfo.setIcon(icon[1].normal[1]);
draginfo.setNumberData(window.getDatabaseNode().ge tChild("castnum").getValue());
draginfo.setShortcutData(getValue());
draginfo.setDescription(getTargetDatabaseNode().ge tChild("name").getValue());

local base = draginfo.createBaseData("shortcut");
base.setShortcutData(getValue());

draginfo.resetType();

return true;
end
</script>
</windowreferencefield>



I have an entry in my spell module that contains the variables "name" and "castnum". The library opens. The subwindow (the one that displays the categories - like "Bard" in the d20 setup) opens. The list opens below it that shows all the spells inside.

I get the error if I try to drag one of the spells rather than open it. The spell opens fine, I just can't drag the link.

A further indicator, is if I drag it to the bar I just get the link graphic, not the name of the spell. If I open the spell and drag it to the bar from the link on that page, it registers in the shortcut bar fine.

I'm sure there is a variable in that script that I'm not referencing properly, I just can't seem to identify it :(

nezzir
May 4th, 2007, 23:38
Fixed by removing
draginfo.setNumberData(window.getDatabaseNode().ge tChild("castnum").getValue());

I have that variable, but it chokes on it for some reason. Anyway, it works now :)

Goblin-King
May 7th, 2007, 08:29
As a general note, something that might be useful related to reading the error message...

Script blocks embedded in the XML files are parsed according to the XML parsing rules first, and as script only afterwards. This means that each entire script block is treated as only one line. There are several consequences:

The error message always refers to line 1 and isn't always that helpful
You can't use the "--" comment syntax, you need to use "--[[ ]]"
You have to end lines with a semicolon even though the Lua specification says it's optional
XML special characters such as ">" and "<" have to be escapedYou can get around all these limitations by putting the script block into a separate .lua file and including that using <script file="..." />.