PDA

View Full Version : Best way to have an "active" checkbox in a list.



eldarune
September 12th, 2020, 01:36
I have added a checkbox to a list to allow the user to pick which weapon is active. See:

39283

When the user clicks on one of the checkboxes, I have written the code to turn the others off.



<button_checkbox name="active_weapon">
<tooltip text="Click to make this the active weapon" />
<script>
<![CDATA[
function onValueChanged()
local name = DB.getValue(window.getDatabaseNode(), "name");
local active = getValue() == 1;

if active then
Debug.console(name .. " is the active weapon.");
for _,v in pairs(window.getDatabaseNode().getParent().getChil dren()) do
if DB.getValue(v, "name") ~= name then
DB.setValue(v, "active_weapon", "number", 0);
end
end
end
end
]]>
</script>
</button_checkbox>


What I would like to know is is this the cleanest approach to achieve this result? Thanks in advance.

Stv
September 12th, 2020, 10:10
Looks like a tidy approach to me, but I'm no code guru :)

Cheers, Steve.