Home | Contents | Index | Help | < Browse | Browse >
Env variables:
--------------
It is possible to make use of env variables anywhere in the script.
They are stated with []-signs around them. So if you have an env
variable with the name color ($color) then you should write [color]
in the selector script. Here is a little example:
Defenv g 6
gap [g]
text "The gap is now: [g]"
button "No Gap" 'setenv g 0' update
button exit 'unsetenv g' exit
Try it!
-------------------------------------------------------------------------
How the variables works.
When the script is loaded (or updated) this is what happens:
1 The next line is loaded.
2 It is seached for any [variables], and they are replaced by the contents
of the real env variables (if there is one). The contents of the env
variable is actually copied into the text line. So the only time you
can change any variables in a selector script is when it is loaded
or updated. You can of course change the real env variables, and then
update selector. This is what is done in the above example.
3 After this, the line is analyzed, and if it is a window command or
startup command, it is executed. If it's an OnChange command, the
contents of the variable to be watched is remembered at this point.
4 When all lines has been gone though, then the window is calculated
and opened. Then the whole script is gone through again, and the
Panel defining commands are analyzed.
This is why you must have the defenv command before the gap [g] command
in the the example above.
The Defenv command sets the env variable g to 6 if the variable g not
allready exists. So 6 is the default value for g.
-------------------------------------------------------------------------
Replacable commands:
Using env variables, you can not only have variable strings and numbers,
but you can change the whole funcionality of the panel by using variable
commands. Try this:
close off
defenv item "button 'Remove button' 'setenv item Text Nothing' update"
[item]
button exit 'unsetenv item' exit
Try it!
Here the command [item] is defined to be a button that replaces itself
with the text string 'Nothing'
-------------------------------------------------------------------------
You can also use env variables to switch some commands off with the
comment sign (;), like this:
close off
defenv c ";"
gap 4
rows 3
startbox
[c] text "Just press"
[c] text "the different"
[c] text "buttons"
endbox
button "Help text" 'setenv c " "' update
button "No Help" 'setenv c ";"' update
button exit 'unsetenv c' exit
Try it!
-------------------------------------------------------------------------
Getting user input to an env variable.
For this, you must use the AmigaDos echo
command and open a new con window:
close off
defenv Me "Boray"
button '[Me]' 'echo >nil: <CON:30/100/400/40/Your_Name to env:Me ?' update
button exit 'unsetenv Me' exit
Try it!
-------------------------------------------------------------------------
Requeststring
Another and a much better way to get user input is to use the external
command Requeststring that also is included in this package. (In the
Tools drawer). This command is made by Adam Dawes and is freeware.
(Requeststring.txt)
Here is the above example using requeststring instead of echo and CON:
close off
defenv Me "Boray"
button '[Me]' 'requeststring >env:Me body "Enter Your Name"
title Request default "[me]"' update
button exit 'unsetenv Me' exit
Try It!
(Please note that the line beginning with "button '[Me]' and the following
line are supposed to be on the same line.)
-------------------------------------------------------------------------
In script, but not in env:
If you have an env variable in your script, and that variable doesn't
exists, then an empty string will be used.
Example:
setenv variable1 "This variable exists!"
text '[variable1]'
text '[variable2]' ;This doesn't...
Try it!
-------------------------------------------------------------------------
Nested? Yes!
Consider this script:
setenv my name
setenv name is
setenv is Boray
text [[[my]]]
Here we have a variable called "my", but when it is replaced by the
contents of "my", we will have:
text [[name]]
After a second replacement:
text [is]
And after the last one:
text Boray
So the text actually written to the window is "Boray".
-------------------------------------------------------------------------
Also see Other variables and shell scripts.
Home | Contents | Index | Help | < Browse | Browse >