Home | Contents | Index | Help | < Browse | Browse >

 The OnChange Command

 This command specifies what
 will happend when an env variable is changed.

 OnChange <variable> [to value | *none* | *any* ]
	 [ EXEC <command> | RUN <command> | ScreenRun <screen> <cmd> 
	 | UPDATE | LOADUPDATE | LOAD <file> [arguments]             
	 | EXIT [<string>] | QUIT [<string>]                         
	 | DumpX <variable> | DumpY <variable>                       
	 | LastX <variable> | LastY <variable>                       
	 | LastXPos <variable> | LastYPos <variable>                 
	 | Popup | PopupClose                                        
	 | Setenv <variable> <value> | UnSetenv <variable> ]         
	 ( ['command 1' 'command 2' ... 'command n'] )               

 The first part (OnChange <variable> [to value]) specifies the
 conditions for the the rest of the commands to execute. <variable> is
 the name of the env variable to be watched for any change. If you specify
 the [to value] option, then the commands are only executed if the variable
 is changed to this specified value.
        DefEnv test "Change Me!"

        Onchange test to end exit
        Onchange test update

        color light
        text "Current value of test is:"
        color dark light
        text "[test]"
        color dark
        button 'Set it to "Hello!"' 'setenv test "Hello!"'
        button 'Set it to "That is cool!"' 'setenv test "That is cool!"'
        button 'Set it to "end"' 'setenv test end'
 This example opens a window with the contents of variable "test".
 Every time the variable is changed, the window is updated. If it
 is changed to "end", the window is closed. You can change the
 variable by pressing the three buttons, or with the setenv command
 from a shell window. The update is not performed right away because
 selector only checks the variables for change every two seconds.
 (But you can change that with VarCheckTime)
 Try it!
 If you now Try it again, you will see that
 the variable allready is set to "end" (you did it a little while ago,
 remember) and the window is not exiting... why? Well, as the commands
 name is "OnChange", selector won't bother because the variable was not
 CHANGED since the moment the script was last loaded or updated. You must
 first set the variable to something else, wait two seconds, and then set
 it to "end" to close the window.
 Also try to start more than one window with the example above, and watch
 how all the windows are updated when you press the button in just
 one of them.

 Observe that you (in the example above) can't place the two onchange
 statements in the opposite order. Then the second statement would never
 be reached. You can look at this as an if....elseif statement.
 There are two special values you can use: *any* and *none*
    OnChange test to *none* exit
 This means that the window will be closed if the env variable "test"
 is unset.
    OnChange test to *any* exit
 This is the same as:
    OnChange test exit
 Another OnChange example: "The Clock"

        x 2000
        y 11

        VarCheckTime 0.8
        exec 'setenv datum `date`'
        onchange datum update
        text "[datum]"

        unsetenv datum
 Try it!
 This script can be quite hard to understand. But it is illustrative for
 how the onchange command works. First the variable "datum"
 is set to the string returned by the amigaOS command "date". Then follows
 the onchange command. It now "remembers" the contents of the variable
 "datum". Then as you can see at the bottom of the script, the variable
 datum is unset. When the whole window is displayed, selector waits about
 one second and then compares the old remembered value of "datum" with
 the current one... Oh.. It is changed!!! to nothing (*none*).
 Now, lets see what to do, I have to update.. yes... And then the
 variable is set again by the exec command, and the whole procedure
 is starting all over again.
 You might want to look at how selector analyses a script.

Home | Contents | Index | Help | < Browse | Browse >