rule of three
July 27th, 2009, 16:41
In all rulesets that were created using the code in adventure_npcs / windowclass name="npc_combat", self.onSizeChanged is call even when the window's size doesn't change.
It may become a problem when a great number of npc are open at the same time.
The problem seems to come from setAnchoredWidth.
I've add a if/then to block the loop :
-initial code - correction in bold -------------------------------------
<windowclass name="npc_combat">
<datasource>npc</datasource>
<script>
--[[ If the size of the window changes, adjust the widths of abilities and saves ]]
function sizeChanged()
local winwidth, winheight = getSize();
local abilitywidth = math.floor(21 + (winwidth - 235) / 6);
if not(abilitywidth == strength.getSize()) then
strength.setAnchoredWidth(abilitywidth);
dexterity.setAnchoredWidth(abilitywidth);
constitution.setAnchoredWidth(abilitywidth);
intelligence.setAnchoredWidth(abilitywidth);
wisdom.setAnchoredWidth(abilitywidth);
charisma.setAnchoredWidth(abilitywidth);
local savewidth = math.floor(47 + (winwidth - 235) / 3);
fortitudesave.setAnchoredWidth(savewidth);
reflexsave.setAnchoredWidth(savewidth);
willsave.setAnchoredWidth(savewidth);
endend
function onInit()
self.onSizeChanged = sizeChanged;
end
</script>
It may become a problem when a great number of npc are open at the same time.
The problem seems to come from setAnchoredWidth.
I've add a if/then to block the loop :
-initial code - correction in bold -------------------------------------
<windowclass name="npc_combat">
<datasource>npc</datasource>
<script>
--[[ If the size of the window changes, adjust the widths of abilities and saves ]]
function sizeChanged()
local winwidth, winheight = getSize();
local abilitywidth = math.floor(21 + (winwidth - 235) / 6);
if not(abilitywidth == strength.getSize()) then
strength.setAnchoredWidth(abilitywidth);
dexterity.setAnchoredWidth(abilitywidth);
constitution.setAnchoredWidth(abilitywidth);
intelligence.setAnchoredWidth(abilitywidth);
wisdom.setAnchoredWidth(abilitywidth);
charisma.setAnchoredWidth(abilitywidth);
local savewidth = math.floor(47 + (winwidth - 235) / 3);
fortitudesave.setAnchoredWidth(savewidth);
reflexsave.setAnchoredWidth(savewidth);
willsave.setAnchoredWidth(savewidth);
endend
function onInit()
self.onSizeChanged = sizeChanged;
end
</script>