Starfinder Playlist
  1. #1

    Best way to have an "active" checkbox in a list.

    I have added a checkbox to a list to allow the user to pick which weapon is active. See:

    Screen Shot 2020-09-12 at 12.24.55 PM.png

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

    Code:
    		<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().getChildren()) 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.

  2. #2
    Looks like a tidy approach to me, but I'm no code guru

    Cheers, Steve.

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
5E Character Create Playlist

Log in

Log in