STAR TREK 2d20
  1. #1

    Join Date
    Mar 2020
    Location
    Sydney, Australia
    Posts
    247

    Options Sheet Text Box

    Hi,

    I have successfully created a textbox control in the Options sheet.

    However, no matter how hard I try can I get an onValueChanged callback to trigger.

    The internal onValueChanged seems to trigger, however the one I registered while registering the Option does not.

    I am pasting relevant code here.

    The Option control I created...based on the Cycler layout.
    Code:
    <?xml version="1.0" encoding="UTF-8"?>
    <root>
    	<windowclass name="option_textbox">
    		<margins control="0,0,0,2" />
            <script>
                local sOptionKey = nil
                local sDefaultValue = ""
                local enable_update = true
    
                function onClose()
                end
    
                function onOptionChanged(sKey)
                end
    
                function setLabel(sLabel)
                	label.setValue(sLabel)
                end
    
                function setReadOnly(bValue)
                	textbox.setReadOnly(bValue);
                end
    
                function initialize(sKey, aCustom)
                	sOptionKey = sKey
    
                	if sOptionKey then
                		if aCustom then
                			sDefaultValue = aCustom.baseval or ""
                		end
    
                		setTextValue(OptionsManager.getOption(sOptionKey))
                	end
    end
    
    function onHover(bOnWindow)
    	if bOnWindow then
    		setFrame("rowshade");
    	else
    		setFrame(nil);
    	end
    end
    
    function getTextValue()
    	local sValue = textbox.getValue()
    	if sValue == "" then
    		sValue = sDefaultValue
    	end
    	return sValue
    end
    
    function setTextValue(sValue)
    	enable_update = false
    
    	if sValue == sDefaultValue then
    		sValue = ""
    	end
    	textbox.setValue(sValue)
    
    	enable_update = true
    end
    
    function onValueChanged()
    	if enable_update and sOptionKey then
    		Debug.chat("New Value -> "..getTextValue())
    		OptionsManager.setOption(sOptionKey, getTextValue());
    	end
    end
    </script>
    		<sheetdata>
    			<stringcontrol name="label">
    				<anchored>
    					<top offset="5" />
    					<left offset="15" />
    					<right offset="-135" />
    				</anchored>
    				<font>optiontitle</font>
    				<static />
    			</stringcontrol>
    			<stringcontrol name="textbox">
    				<anchored width="100">
    					<top offset="5" />
    					<left parent="label" anchor="right" offset="25" />
    				</anchored>
    				<center />
    				<font>optionbody</font>
    				<script>
    					function onValueChanged()
        					window.onValueChanged();
    					end
    				</script>
    			</stringcontrol>
    		</sheetdata>
    	</windowclass>
    </root>
    I set the callbacks for the options in a LUA file like this ... note that I use a factory to generate my register functions so value, key & callback are previously defined names/functions. I know this works because it is working for the cyclers associated with the texbox.

    Code:
        OptionsManager.registerOption2(
            key, true
            , group, label, "option_textbox"
            , { baselabel = value
                , baseval = Interface.getString(value)
                , default = Interface.getString(value)
            }
        )
    
        OptionsManager.registerCallback(key, callback) <--- this is the callback that does not seem to fire (I have debugs in that function to announce the firing).
    Any help/insight appreciated.
    Thanks In Advance,
    D

  2. #2

    Join Date
    Mar 2020
    Location
    Sydney, Australia
    Posts
    247
    I have solved the problem ... seems I had a single character typo in my scripting and thus it was failing to find the correct callback function.
    Thanks In Advance,
    D

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
  •  
DICE PACKS BUNDLE

Log in

Log in