PDA

View Full Version : Problems Deleting Windowinstance



Myrddin
January 1st, 2016, 11:13
Happy New Year one and all!

I am having problems trying to program a windowlist to automatically delete entries once their values hit zero. My code for the windowclass is below. At the moment, FG crashes once I adjust the value of a wound entry to zero, presumably because I am creating an infinite loop with the if getValue() == 0 statement. Any pointers anyone?


<windowclass name="charsheet_woundlistitem">
<sizelimits>
<minimum>
<height>30</height>
<width>0</width>
</minimum>
</sizelimits>
<sheetdata>
<number_dropadd name="wound">
<droptypes>
<type merge="add">damage</type>
</droptypes>
<bounds>5,6,22,16</bounds>
<min>0</min>
<script>
local bProcessing = false;

function onValueChanged()
if bProcessing then
return;
end
bProcessing = true;
if getValue() == 0 then
window.getDatabaseNode().delete();
end
bProcessing = false;
end
</script>
</number_dropadd>
</sheetdata>
</windowclass>

damned
January 2nd, 2016, 11:33
is it possible its the delete that it doesnt like - try changing that action to something else?
window.getDatabaseNode().delete();

Myrddin
January 2nd, 2016, 12:45
Thx damned, but no joy I'm afraid. I tried window.getDatabaseNode().destroy(); as well, but that gives an attempt to call field 'destroy' (a nil value) script error

Moon Wizard
January 3rd, 2016, 01:21
There's similar logic in the code that removes effects after they are decremented in both the 3.5E and 5E rulesets.

My guess is that deleting the source database node in the onValueChanged event causes the crash. You'll most likely have to capture at a different level using a DB.addHandler call. There are also several examples of these calls in the 3.5E and 5E rulesets.

Regards,
JPG