When a program is exited with an exit or a change to program action statement, any changes that took place during execution are abandoned; when that program is run again, it is run exactly as it was written. But by specifying the save program as action statement before any exit or change to program statement is encountered, you can save the program, with the changes made during execution, to a new ESL binary program file. (This statement does not terminate the currently executing program.) Note that the save program as statement can be used in an action routine but not in a subroutine. Like other action statements, this statement can be specified in a response definition or an action routine definition.
When an ESL program is executed, changes might be made to object attributes and/or to the local variable values; new objects might be created, or the composition of classes might change. For example, when Square is selected, the key Bubble, which was red, is changed to the color green:
red key Bubble ...
response to Square
make Bubble green
exit
Bubble will be red, not green, when the program is run a second time. In contrast, the save program as statement saves the program in its current state. All objects are saved with their current appearance, attributes, and text and graphics cursor positions; local and global variables are saved with their current values. Thus, if a save program as statement is executed before the exit statement
red key Bubble ...
response to Square
make Bubble green
save program as "revised.web"
exit
If Square is selected, Bubble will be green, not red, when the compiled program REVISED is run. Any other changes that were made during execution of the program are also saved in the compiled REVISED file.
Note that the save program as statement can be used in an action routine but not in a subroutine.
When you save a program, the program currently executing still exists as it was written, and continues to run until an exit or change to program statement is executed. The new program, as amended during execution, has been saved in a new file, identified by the specified value for PROGRAM_NAME. If you are going to transfer control to this binary program file, be sure that the name includes the extension .WEB. But be careful if you specify a save program as statement with the same name as any other existing ESL binary file, including the one that is currently being executed, the saved program will overwrite the original program.
The saved program does not have to be in the current directory; you can specify a full pathname for it. When specifying a path, include an extra backslash each time one is specified; for example:
save program as "c:\\ESL\\second.web"
since a single backslash is the escape character in an ESL string literal.