PDA

View Full Version : Can I use some kind of merge extending scripts?



meathome
February 23rd, 2014, 07:15
I wanted to limit the number of slots per row for the core rpg buttongroup_counter. There is already a variable defined for it so I tried changing that from the script block of my control but neither its name (nMaxSlotRow) nor super. + the name gave me access to the variable. So I ended up simply copying the whole control, giving the template and merge="replace" property and then adding the following to the onInit() of the copied script file:



if maxslotrow then
nMaxSlotRow=tonumber(maxslotrow[1]);
end


Now I can set it like I wanted from a field in the xml. Is there a more elegant way than copying the whole template + script form core rpg?

Trenloe
February 23rd, 2014, 10:10
I wanted to limit the number of slots per row for the core rpg buttongroup_counter. There is already a variable defined for it so I tried changing that from the script block of my control but neither its name (nMaxSlotRow) nor super. + the name gave me access to the variable.
You can't access nMaxSlotRow from outside of buttongroup_counter.lua because it is defined as "local":

local nMaxSlotRow = 10;


So I ended up simply copying the whole control, giving the template and merge="replace" property and then adding the following to the onInit() of the copied script file:



if maxslotrow then
nMaxSlotRow=tonumber(maxslotrow[1]);
end


Now I can set it like I wanted from a field in the xml. Is there a more elegant way than copying the whole template + script form core rpg?
Because you'll need to change the nMaxSlotRow variable somehow, even if it is to just remove the "local" variable scope from nMaxSlotRow, you'll need to include the whole, modified script in your extension/ruleset (I would suggest with a different name, e.g. buttongroup_counter_MyExt.lua

Then you'll need to change the <script> tag somewhere to use this modified lua file instead of the base CoreRPG one, e.g. <script file="common/scripts/buttongroup_counter_MyExt.lua" /> As this is defined within the control XML template you can use the standard XML merge rules to just change this as required - either changing the underlying template itself, or making a new template or when you use the control.

You don't need to copy the whole template as you can use merge="replace" to change just the <script> tag. You do need to include the whole LUA file as this does not support merging.