How can i shorten this code?
My neverending quest of designing my custom ruleset continues...
This time i have been successful in finish the character sheet and its features. However, i think it's not really optimized. There's a ton of repetitive code for each of the many attributes of the sheet, the only difference being the name of the attribute itself in the code. I would like to make a custom script that would take all this repetitive functions in one place, so i could pass just one single parameter on each attribute, instead of repeating the whole code.
This is an example:
Code:
<specialization name="str_spec">
<script>
function onInit()
if getValue() == "" then
setValue("No Specialization")
else
window.strength.setTooltipText(getValue())
end
end
function onValueChanged()
window.strength.setTooltipText(getValue())
end
</script>
</specialization>
<stringcontrol name="strength">
<anchored>
<to>frame_physical</to>
<position>insidetopleft</position>
<offset>25,28</offset>
</anchored>
<static>Strength</static>
<script>
function onDoubleClick()
local value = window.str_points.getValue()
local dicepool = ChatManager.d10Check(value)
local diff = 6 + ModifierStack.getSum()
if Input.isShiftPressed() then
window.pool.setValue(value)
window.pool_name.setValue(getValue())
else
ActionsManager.performRoll(nil, nil, "Strength", diff, bSecretRoll, dicepool)
end
end
function onDrop(x,y,dragdata)
if Input.isControlPressed() then
window.str_spec.setValue("Speciality: " .. dragdata.getStringData())
end
end
</script>
</stringcontrol>
<standard_points name="str_points">
<anchored>
<to>strength</to>
<position>insidetopleft</position>
<offset>95,-2</offset>
<size>
<width>50</width>
<height>20</height>
</size>
</anchored>
<default>1</default>
</standard_points>
If, let's say, i start a new file and register it as "CustomScript:
How could i take these repetitive scripts in a way that i could just call a function like CustomScript.shorten("attribute_name") instead of repeat the whole code? I tried myself but i having trouble in figure out how can i make so that this new file knows where the node is when a function calls it from another file...
(as you can see, i have limited LUA and FG structure knowledge. Please, be patient with me... ;) )