Scripted GUI logic

While connecting properties as described above is often enough, sometimes it is more flexible or more convenient to use JS to script the GUI logic. In this way, the above example could be re-written as:

	<code file="code.js"/>
			// ECMAScript code in this block
			// the top-level statement is only called once
			gui.addChangeCommand ("mode.string", "modeChanged ()");

			// this function is called whenever the "mode" was changed
			modeChanged = function () {
				var varmode = (gui.getString ("mode.string") == "variable");
				gui.setValue ("y.enabled", varmode);
				gui.setValue ("constant.enabled", !varmode);

	<dialog label="T-Test">

The first line of code tells RKWard to call the function modeChanged() whenever the value of the id="mode" radio box changes. Inside this function, we define a helper-variable "varmode" which is true when the mode is "variable", false as it is "constant". Then we use gui.setValue() to set the enabled properties of "y" and "constant", in just the same way as we did using <connect> statements, before.

The scripted approach to GUI logic becomes particularly useful when you want to change the available option according to the type of object that the user has selected. See the reference for available functions.

Note that the scripted approach to GUI logic can be mixed with <connect> and <convert>-statements if you like. Also note that the <script> tag allows to specify a script file name in addition to or as an alternative to inlining the script code. Typically, inlining the script code as shown above is most convenient, however.