PDA

View Full Version : Trouble with Anatomy of a ruleset.



enygma
February 9th, 2011, 23:45
I'm stuck at the end of chapter 2. If I put the script into the characteristics window, it crashes to desktop with no error. If I delete whats in enclosed to script the characteristics window is blank as I would expect, but no crash.

The ungraceful crash to desktop is a bit annoying, I wish it would pop something up saying i'm an idiot or something.

Is the script in the tutorial outdated or am I just doing it wrong. Here's what my script code looks like:



<windowlist name="characteristics">
<anchored>
<to>characteristicframe</to>
<position>over</position>
<offset>-15,-20</offset>
</anchored>
<class>charsheet_characteristic</class>
<datasource>.characteristics</datasource>
<noscroll/>
<script>
STR = nil;
CON = nil;
DEX = nil;
SIZ = nil;
INT = nil;
POW = nil;
CHA = nil;
local order = 1;
function addEntry(name, label)
local node = getDatabaseNode().getChild(name);
local win = nil;
if not node then
node = getDatabaseNode().createChild(name);
end
for i,w in ipairs(getWindows()) do
if w.getDatabaseNode().getName()==name then
win = w;
end
end
if win then
win.label.setValue(label);
win.order.setValue(order);
order = order + 1;
end
return win;
end
function onSortCompare(w1, w2)
return (w1.order.getValue() &gt; w2.order.getValue());
end
function onInit()
STR = addEntry("STR","STRength");
CON = addEntry("CON","CONstitution");
DEX = addEntry("DEX","DEXterity");
SIZ = addEntry("SIZ","SIZe");
INT = addEntry("INT","INTelligence");
POW = addEntry("POW","POWer");
CHA = addEntry("CHA","CHArisma");
applySort();
end
</script>
<skipempty/>
</windowlist>

kairos
February 10th, 2011, 01:35
Hi, enygma:

I just went through that tutorial recently and had no problem with it (other than trying to figure it out). Have you tried moving that inline script into a lua file and seeing if it debugs? That is, replace your script with this line:


<script file="scripts/charsheet_characteristicsInit.lua"/>

Then paste your code into that file and /reload the ruleset to see if the console lists any debug information.

(You might also try restoring down the FG window, then typing /console to open the debug window.)

Brian

enygma
February 10th, 2011, 01:52
I'll try that thanks

StuartW
February 10th, 2011, 06:41
If you move the script to a file, remember to change the & g t ; sequence in onSortCompare to a greater-than (>) symbol: inline code has to use xml-escaped symbols, but external code cannot use them.

Another debug trick is to comment out sections of code to narrow down where the problem is. In lua a comment begins with --[[ and ends with ]] but if your code is in a separate file you can use single line comments, where the -- sequence comments out the remainder of the line. Single line comments don't work in inline code.

Stuart