Intellicomm (TM) v2.01 Copyright (C) 1991-1994 Liberation Enterprises. All rights reserved. --------------------------------------------------------------------- INTELLICOMM SCRIPT LANGUAGE TUTORIAL --------------------------------------------------------------------- TABLE OF CONTENTS 1. INTRODUCTION . . . . . . . . . . . . . . . . . . . . . . . . . . 1 1.1 What are Scripts? . . . . . . . . . . . . . . . . . . . . . 1 1.2 Why Should I Bother With Scripts? . . . . . . . . . . . . . 1 1.3 Is This Going to Take HOURS? . . . . . . . . . . . . . . . . 2 1.4 Script Learn Mode . . . . . . . . . . . . . . . . . . . . . 2 1.5 How Do I Create a Script? . . . . . . . . . . . . . . . . . 3 1.6 Icom's Internal Editor vs. an External Editor . . . . . . . 4 1.7 Stopping Scripts . . . . . . . . . . . . . . . . . . . . . . 4 1.8 Creating and Running Your First Script . . . . . . . . . . . 5 1.9 A More Exciting Example . . . . . . . . . . . . . . . . . . 6 1.10 Other Ways of Running Scripts . . . . . . . . . . . . . . . 8 1.10.1 Running Script from BIFs (8); 1.10.2 Running Scripts from Jobs (8); 1.10.3 Running Scripts from DOS (9); 1.10.4 Running Scripts from Scripts (9); 1.10.5 Running Scripts from the Script Manager (9); 1.10.6 Running Scripts via Function Keys (10) 1.11 It Can't be That Simple, Can It? . . . . . . . . . . . . 10 1.12 Variable Overview . . . . . . . . . . . . . . . . . . . . 15 1.13 A Word on Formatting . . . . . . . . . . . . . . . . . . 18 1.14 Why the Double Quotes ""? . . . . . . . . . . . . . . . . 19 1.15 Specifying Control Characters . . . . . . . . . . . . . . 19 1.16 Tildes . . . . . . . . . . . . . . . . . . . . . . . . . 20 1.17 Specifying Numbers . . . . . . . . . . . . . . . . . . . 20 1.18 Numeric Limits . . . . . . . . . . . . . . . . . . . . . 21 1.19 Compound Statements . . . . . . . . . . . . . . . . . . . 21 1.20 Where To Go From Here . . . . . . . . . . . . . . . . . . 23 1.21 The Secret to Success . . . . . . . . . . . . . . . . . . 24 2. WHAT HAPPENS WHEN A SCRIPT ENDS? . . . . . . . . . . . . . . . 26 2.1 EXIT and RETURN Error codes . . . . . . . . . . . . . . . 27 2.2 Using the HANGUP Command for Error-Recovery . . . . . . . 28 3. INTRODUCTION TO SUBROUTINES (GOSUB) . . . . . . . . . . . . . . 28 3.1 When to use a Subroutine . . . . . . . . . . . . . . . . . 28 3.2 Writing a Subroutine . . . . . . . . . . . . . . . . . . . 29 3.3 GOSUB In Detail . . . . . . . . . . . . . . . . . . . . . 30 3.4 Creating a Subroutine Template . . . . . . . . . . . . . . 31 4. SCRIPT VARIABLES IN DETAIL . . . . . . . . . . . . . . . . . . 32 4.1 Why Would I Want to Use Variables? . . . . . . . . . . . . 32 4.2 Where you CAN'T use Variables . . . . . . . . . . . . . . 32 4.3 User-Defined Variables . . . . . . . . . . . . . . . . . . 32 4.4 User-Defined Variable Rules . . . . . . . . . . . . . . . 33 4.5 Why All the Rules? . . . . . . . . . . . . . . . . . . . . 35 4.6 Using Variables . . . . . . . . . . . . . . . . . . . . . 36 4.7 The Life of a Variable . . . . . . . . . . . . . . . . . . 37 4.8 Global Variables . . . . . . . . . . . . . . . . . . . . . 38 Intellicomm v2.01 SCRTUTOR.DOC ii 4.9 Using Global Variables . . . . . . . . . . . . . . . . . . 40 4.10 Passing Parameters to Scripts . . . . . . . . . . . . . . 41 4.11 Checking the Number of Passed Parameters . . . . . . . . 43 4.12 System Variables . . . . . . . . . . . . . . . . . . . . 44 4.13 BIF Variables . . . . . . . . . . . . . . . . . . . . . . 45 4.14 Main Setup and Environment Variables . . . . . . . . . . 45 4.15 Environment Variables . . . . . . . . . . . . . . . . . . 45 5. PERMANENT VARIABLES: INTRODUCTION TO FILE INPUT/OUTPUT . . . . 46 5.1 FOPEN 'Modes' . . . . . . . . . . . . . . . . . . . . . . 47 5.2 The File Handle . . . . . . . . . . . . . . . . . . . . . 48 5.3 Testing for End-of-File . . . . . . . . . . . . . . . . 53 5.4 How to store settings on-disk . . . . . . . . . . . . . . 53 5.5 Moving the File Pointer (Advanced Use Only) . . . . . . . 54 5.6 Opening a File for Reading AND Writing (Advanced use only) 57 5.7 Upating an Old Data File . . . . . . . . . . . . . . . . . 59 6. INTRODUCTION TO DATABASE COMMANDS (FILE TAGGER CATALOGS) . . . 62 6.1 Why would I want to use the catalog-oriented commands? . . 62 6.2 What is a Database? . . . . . . . . . . . . . . . . . . . 62 6.3 Indexes . . . . . . . . . . . . . . . . . . . . . . . . . 63 6.4 Using File Tagger Indexes . . . . . . . . . . . . . . . . 64 6.5 How this all applies to Scripts . . . . . . . . . . . . . 65 6.6 The View Date . . . . . . . . . . . . . . . . . . . . . . 70 6.7 Getting Around in a Catalog . . . . . . . . . . . . . . . 71 6.8 Getting the Total Number of Records . . . . . . . . . . . 72 6.9 The View Date and Tagged/Noted Files . . . . . . . . . . . 73 7. USING THE SCRIPT DEBUGGER . . . . . . . . . . . . . . . . . . . 74 7.1 What are BUGS, and What is a DEBUGGER? . . . . . . . . . . 74 7.2 Using the Debugger . . . . . . . . . . . . . . . . . . . . 75 7.3 Checking the Contents of a Single Variable . . . . . . . . 77 7.4 Debug Hotkeys . . . . . . . . . . . . . . . . . . . . . . 78 Intellicomm v2.01 SCRTUTOR.DOC 1 1. INTRODUCTION 1.1 What are Scripts? Scripts are files which contain one or more instructions (commands) for Intellicomm to carry out. You can't 'talk' to Intellicomm to tell it what to do when you have custom work to do (at least, not to my knowledge... ), so the next best thing is to write it down and let Intellicomm read it. As a movie script tells the cast what to say and do: Intellicomm scripts tell Intellicomm what to say and do. You're the script writer and Intellicomm is your cast. Don't confuse scripts with Icom's automated jobs and BIFs. The jobs you run from the Job Directory and set up in the Job Editor are not scripts; they're called Jobs and they are carried out by ICOM.EXE's built-in automated routines, using BBS Information File (BIF) data. Jobs are jobs, BIFs are BIFs, and scripts are scripts. They're three different things, and this document discusses scripts only. For information on Icom's internal jobs (automated file uploads and downloads, mail transfers and time bank transactions, etc.) please refer to the online help, and particularly to "BIF Learn". 1.2 Why Should I Bother With Scripts? There are limitless benefits awaiting those who learn some (or all) of Intellicomm's script language, and learn the simple process of creating scripts. Most importantly, you will gain an incredibly flexible and powerful tool to add to your automation arsenal. Virtually ANYTHING you can dream up can be automated with a script, while BIFs and automated jobs (aside from the job "Custom Commands" which allow limited custom work) were designed for specific tasks. With scripts you can automate *any* BBS task by watching for specific text from the BBS and handling it as you see fit (send responses to the BBS, transfer files, display information on the screen, and do any number of other things). If desired, you can easily define your own custom interfaces using menus and other interactive functions for interactive user input, you can display multiple boxes/windows and other text on the screen (including the ability to display incoming text from the *BBS* in a window) using a bevy of powerful video-oriented script commands, you can run other DOS programs (or .BAT files, or other Icom scripts), pause script execution until a specific time and/or day, create, display, and otherwise maintain File Tagger catalogs in every way imagineable, read from and write to text files on-disk (save information permanently), display text files in the File Viewer or load them into the Editor for the user to view/modify, test for certain system conditions (date, time, day-of-week, etc.), get and set BIF and Icom main setup information, create 'keyboard macros', and on and on. Those who gain control over both Icom's built-in jobs AND its script language (and script learn mode, for registered users) truly have the most powerful and flexible set of tools available for automated BBS communications, probably anywhere in the universe. If automation, and Intellicomm v2.01 SCRTUTOR.DOC 2 taking the drudgery out of your online sessions is your passion, you can't beat that prospect! 1.3 Is This Going to Take HOURS? Don't be discouraged by the size of the script manuals. The script language and manuals are like a big bowl of peanuts: take what you want. You don't have to eat the whole bowl to enjoy yourself and get something useful done, and you'll be able to write very useful scripts after reading just the next few pages below. If you just want the basics, and the basics are VERY powerful and useful indeed, you should be finished in half-an-hour or less. If you end up drooling at the possibilities and want the whole bowl of peanuts, it'll take some practice (and some more reading) to get the whole language down. But it's your choice, and making progress and getting things DONE is a quick process as you'll soon see. You don't even have to print this document if you don't have the time or paper: Just read it in the help system ("SCRTUTOR.DOC" link; make sure SCRTUTOR.DOC is in the same directory as ICOM.EXE) or text viewer (via the Icom File Manager / "View" option) until you're satisfied with what you've learned. The script documents should be used as follows: 1. Read the introductory material in this document until you're happy with what you've learned. This document gives you the basics and, more importantly, shows you how to put script commands together to get something practical done. 2. Once you've got the basics down, use the "SCRIPT COMMANDS AT A GLANCE" section at the beginning of SCRIPT.DOC to find the command(s) you're interested in, and to refresh your memory as to what various commands do. 3. When you find the command you want, using step 2 above, look it up in the DETAILED COMMAND SUMMARY (sorted alphabetically by script command) in SCRIPT.DOC to quickly get all the details along with an EXAMPLE showing how to use the command. TIP: If you view SCRIPT.DOC from Icom's internal File Viewer or help system, to locate a command summary press [Alt-F] (Find) then type the command you're interested in, follow that with an underscore (e.g. PRINT_) then carry out the search DOWNWARDS to find the Detailed Summary in a flash. All commands in the Detailed Command Summary of SCRIPT.DOC are followed by a line of underscores to allow you to find commands quickly. The Table of Contents, and the index at the back of the manuals can also be used to locate information quickly. Many people skip the Table of Contents, but you can learn a lot by looking at it carefully. You'll see how the manuals are laid out, and more importantly can quickly see every major topic that is covered -- which can be useful to know when you have a question later. 1.4 Script Learn Mode The easiest way to become acquainted with scripts is to use Icom's script Intellicomm v2.01 SCRTUTOR.DOC 3 learn mode (a bonus feature in the registered version). With script learn mode you simply turn it on, then just 'do' whatever it is you want automated. Icom watches what you do and writes a script for you! Not only do you save time getting your scripts written, but it's also quite educational: by looking at the script Icom creates, you can learn how the script language works. Script Learn is accessed through the "Learn Modes" option of the Main Menu or Job Directory or Terminal "Tools" menu, and in various other places. Pressing [Alt-Q] from just about anywhere in Intellicomm calls up the Learn Modes menu. Use of Script Learn is quite straightforward, and is covered in the online help if you have questions. 1.5 How Do I Create a Script? Writing a script (or modifying/adding to one started with Script Learn) is much the same as typing a letter in your word processor. Instead of using a word processor though, which places printer commands and formatting codes all over the document, you instead use a "Text Editor" to create scripts. Text Editors work similarly to word processors as far as typing, deleting, cutting/pasting text, etc. But they don't add printer codes to the files you save to disk -- and they usually don't force margins on you, which is essential for writing scripts. Script command lines will sometimes be longer than your screen width, and thus the margins in word processors which 'wrap' long lines are not acceptable. The files Text Editors produce are called "text files", or "ASCII files" and these are the types of files Icom requires for scripts -- without any printer formatting codes or margins. Intellicomm comes with a built-in Text Editor, though you can use your favorite external Text Editor if you like (details in a second). For script writing, the editor (whether internal or external) is best accessed through the Icom "Script Manager". By accessing the Script Manager first you can be sure that your scripts will be saved in the proper directory; since Icom changes DOS to the Script Directory (\ICOM\SCR by default) when you enter the Script Manager. From the editor you just save your scripts in the current directory (without specifying a drive letter or \DIRECTORY\ name), and they always end up in the right place, where Icom expects them to be. The Script Manager can be accessed from the Icom Main Menu (and at various other menus), or by simply pressing [Alt-U] from just about anywhere in Intellicomm. [Sorry about the 'U'; it doesn't help much in remembering the key, but unfortunately [Alt-S] (S for Script) is a fairly standard 'Screen Capture' command and is used by the Terminal.] Once in the Script Manager, select "Create" from the bottom menu to create a new script, or hilight the script of interest and select "Edit" to view/modify an existing script, or hilight a script and select "Run" to execute it (the other options in the Script Manager are fairly self- Intellicomm v2.01 SCRTUTOR.DOC 4 explanatory... please see the online help if you need more information). There are several scripts included with Intellicomm for demonstration and other purposes. You can enter the Script Manager, hilight and "Run" SCRDEMO.SCR from the Script Manager now if you want to see a script in action before you continue reading. SCRDEMO.SCR can also be viewed after you run it, for many useful examples. Note that Intellicomm itself doesn't use SCRDEMO.SCR for anything, so you can delete the file when you're done with it, if you're short on disk space. 1.6 Icom's Internal Editor vs. an External Editor If you use Icom's internal Text Editor, you gain the advantage of online script writing help (online access to the documentation). So, when you forget one of the script commands we'll be discussing below you can simply press the [F1] help key, and call up the index of script help. You can view this document (if installed in the \ICOM directory) or SCRIPT.DOC to obtain any information you require, without leaving the editor by accessing the SCRTUTOR.DOC or SCRIPT.DOC help links (available from the "Script Language" Index, and various other places). A further advantage of using the internal editor is that if by chance you make a typing mistake in your script, then Run the script before noticing the error; Icom will be able to load the script into the internal editor, position the cursor right on the line of the script where the error occurred, displaying the error message to you so you can fix it. With an external editor Icom will still call your editor if an error is found, and if your editor accepts a filename on the command line the script will be loaded for you, but you won't be moved to the proper line number. You can get the error message (which includes the number of the line on which the error occurred) from the file \ICOM\SCRIPT.ERR while in your external editor, but unless you're proficient with your external editor and are used to doing this sort of thing (with other script languages or program compilers), you're probably better off using Icom's internal editor for the time being. To use an external editor you must define the editor command in the Icom main setup (accessed via the main menu "Intellicomm Setup" option), on the "Filenames and Paths" screen. Hilight the "Extnl Editor" item, then press [Enter] and enter the command you'd normally use to start your editor from the *DOS command prompt* there, and save your setup. Icom will then call your external editor when you select "Create" or "Edit" from within the Script Manager or when a script error occurs. If you defined an external editor previously and wish to reverse your decision for now and use the internal editor, do the same as outlined above but CLEAR the "Extnl Editor" item in the main setup (hold down the [Del] key until the item is clear, or press [Ctrl-End] once to clear the item while editing it), then re-save your setup. Icom will then use its internal text editor. 1.7 Stopping Scripts Before we create and run a script, it'll be useful for you to first know Intellicomm v2.01 SCRTUTOR.DOC 5 how to STOP one, if something goes wrong. To stop a script, just press [Alt-Q] (Q for Quit), relax (the script is paused while you're in the [Alt-Q] menu or any other menu) then select "Abort Script Only" to cancel the script without cancelling the entire job (if the script was called during an automated job... more on that later), or select "Abort Job/Script" to cancel both the script and the job. To activate script debugging, which runs a script one line at a time, showing you each line before it is executed select "Script DEBUG" from the [Alt-Q] menu. Script debug can also be helpful in learning script writing, since it slows script execution down, allowing you to study each command before it is executed, and see its result after it is executed. If you forget the [Alt-Q] command, just press [Alt-Z] to pop up the Terminal menu (the terminal is where all scripts are executed from, regardless of where they're started from) and select "Job and Script Control Menu" from the menu, which has the same effect as pressing [Alt- Q] from the Terminal. [Alt-Z] can be your panic button if you forget the [Alt-Q] key. 1.8 Creating and Running Your First Script Most computer language tutorials begin by showing the student how to print the message "Hello, World" to the screen. It's a quick way to actually accomplish something, so we'll start by doing this here as well. To begin, start Icom if necessary, then access the Script Manager by pressing [Alt-U]. If [Alt-U] doesn't work, then you're in an area of Icom where the hotkeys are disabled, and you'll have to exit that area back to any 'major' Icom area, then try again. Note that these "follow along while reading" bits are very quick, so if you're considering printing this document now, don't (unless you don't mind doing so). For 99% of the tutorial you will simply read along in the online help or File Viewer, (without wasting paper) without 'doing' anything but learning. Just grab a piece of paper and write the few short script lines down before exiting this document and entering the Script Manager. Writing the commands down also helps the brain to remember things better. From the Script Manager select "Create" to enter the editor (whether internal or external) to create a new script. Once in the editor type the two lines below, pressing the [Enter] key after each line. If you make a mistake, use the backspace key (just above the [Enter] key) to correct it. Case is not significant when entering script commands; 'PRINT', 'Print', and 'print' all do the same thing. Use whichever you prefer: print "Hello, World!" pause Once you have these two lines entered, save the file as HELLO.SCR and exit the editor (from Icom's internal editor, just press the [Esc] key to exit, answer "Yes" when asked if you want to save your work, then enter HELLO.SCR when asked for a filename. You're on your own if you're using an external editor. See your editor's help screens if you don't know how Intellicomm v2.01 SCRTUTOR.DOC 6 to save and exit.) If you're asked whether to overwrite an existing file, someone probably gave you a copy of Intellicomm that had already been "used" (they already read this and created their own HELLO.SCR). If that's the case just overwrite the existing file when asked. Once you return to the Script Manager you should see HELLO.SCR displayed in the list of script filenames. To execute the script, move the top hilight bar to HELLO.SCR with the [Up] / [Down] cursor keys (or move the mouse cursor to HELLO.SCR and click), then select "Run" from the bottom menu by pressing the [R] key, or by moving the mouse cursor to "Run" and clicking. Intellicomm should then switch to the Terminal screen, print the message Hello, World! to the screen, and pause for a keystroke. When you press a key the script will end and you will be returned to the Script Manager. Did it work? If so, congratulations! If not, please start over, and check your typing carefully. You may have missed a " quote or left a space out accidentally. 1.9 A More Exciting Example It's nice to be able to print the message "Hello, World" to the screen, but it certainly isn't very impressive or exciting. Let's try something a little more interesting this time. You know what 'menus' are if you've been using Icom for any length of time, and now it's time to demonstrate how easy it is to create a menu using an Icom script. You may even impress your friends or co-workers with this next script! Select "Create" again from the Script Manager to enter the editor and create a new script, then type in these three lines exactly, double- checking all the quotes, spaces and tildes (~): MENUDEFINE "Option ~1" "Option ~2" "-" "Option ~3" "Option ~4" MENUBOXV "My Own Menu" "Your selection, Sir?" PAUSE "You selected Option " $MENUSELECTION When done, save the script to disk but this time as MENU.SCR (from the internal editor, press [Esc], answer "Yes" to save it, then enter MENU.SCR when asked for a filename; again overwrite if a MENU.SCR already exists). When you return to the Script Manager, hilight MENU.SCR and select "Run" to see what you've created. If you entered the lines above exactly, you'll have created a centered box menu, with title, four menu options with a divider line separating items 2 and 3, hotkeys, and mouse support! Of course, the menu doesn't actually 'do' anything yet other than print which option you selected (or 0 if you press the [Esc] key)... you'd have to add a few more lines to the script to get the options to do something. However, just being able to display such a menu on the screen with working hilight bars and mouse support (and even a screen blanker, if Intellicomm v2.01 SCRTUTOR.DOC 7 that feature is turned on in the Icom main setup) is no small programming task. Yet you accomplished it in about 30 seconds! We used "Option ~1" and so forth above, but the options can be any text you like; as long all the options remain on the same line, each in double quotes, separated from one another by a space. The "~" character tells MENUDEFINE where the 'hotkey' is. Using a single hypen "-" as a menu option specifies a divider line. $MENUSELECTION is a 'System Variable' which Icom sets after menu-handling commands to tell you which (if any) item was selected from the menu. There are about a hundred of these System Variables available (all starting with $) and each is documented fully in SCRIPT.DOC. By testing the $MENUSELECTION variable with an IF or SWITCH command, you could have various other commands carried out according to the menu option the user selected. Example (text after a semicolon ; is ignored by the script processor and is used to make comments for human consumption): ;The first IF means "IF $MENUSELECTION is equal to 1" If it is, then ; the command following the IF is executed. If not, the command is ; skipped. IF $MENUSELECTION = 1 print "Downloading file..." ;these commands are only download "Z" "" ; executed IF $MENUSELECTION ...etc. ; is equal to 1 ENDIF IF $MENUSELECTION = 2 gosub Item1Selected ;go to a subroutine A better way to test the value of $MENUSELECTION though is to use the SWITCH command. SWITCH is designed specifically to test a variable such as $MENUSELECTION for multiple conditions, and to carry out one command (or set of commands) according to the value of the variable. Read the comments (after ;) for an explanation: SWITCH $MENUSELECTION ;specify the variable to test case 1 ;is $MENUSELECTION equal to 1? print "Option 1 selected" ; yes, print this ... ; execute as many commands as you like endcase ;'end of case 1' (the rest are skipped) case 2 ;is $MENUSELECTION equal to 2? print "Option 2 selected" ; yes, print this ... ; and execute whatever commands you like endcase ;'end of case 2' (the rest are skipped) ... ;and so on with as many 'case/endcase' as ; needed default ;default is an optional 'case' that is ... ; carried out if no other cases are true endcase ;end of 'default' case ENDSWITCH ;mandatory 'end of switch' statement If $MENUSELECTION was equal to 1 (i.e. if the user had selected option 1 from the menu) then ONLY the command(s) between "case 1" and its Intellicomm v2.01 SCRTUTOR.DOC 8 "endcase" would be executed. Note that "case 1" isn't fixed text. You won't always use "case 1", "case 2", etc. In some cases you might use this: case ".ZIP" ;is the SWITCH equal to ".ZIP"? endcase case 12345 ;is the SWITCH equal to 12345? endcase ...etc. Only the word "case" is fixed. Whatever follows the word "case" is compared to the variable specified in the SWITCH ($MENUSELECTION in this example) and if they're equal then the commands between that case/endcase are carried out. If they aren't equal, the case (to its ENDCASE) is skipped, and the next 'case' is checked. When you're ready for more information on using menus, see the MENUDEFINE, MENUBAR, MENUBOXH, MENUBOXV, IF and SWITCH in the DETAILED COMMAND SUMMARY section of SCRIPT.DOC. Also see SCRDEMO.SCR and POSTFILE.SCR for practical examples of menu and SWITCH usage. 1.10 Other Ways of Running Scripts The scripts you just wrote, as with any Icom script, can be executed in all sorts of different ways. You can run them from BIFs, from Jobs, from the DOS command line (using a .BAT file or menu system, for example), from another script, or from the Script Manager. 1.10.1 Running Script from BIFs Scripts can be executed from a BIF by simply specifying @SCRIPTNAME as the response to a prompt: | Your Logon Name> @HELLO Name . . . . . . st Name? ® | ^^^^^^ Another useful way to run a script from a BIF is via the "Connect Command" item on BIF screen 1. This command (or @SCRIPTNAME) is executed as soon as Icom connects to the BBS, before it gets any logon prompts. 1.10.2 Running Scripts from Jobs Scripts can also be executed by a job "Custom Command" (defined in the Icom Job Editor, where you define all your automated jobs) again by specifying @SCRIPTNAME as the Custom Command: | 12 Custom Command/Run script | CC: @MENU | ^^^^^ The above two methods of running scripts allow you to run any script just about ANYWHERE during an automated job. Note that the .SCR extension is not specified in the examples above. You 'can' specify the extension if you like, but Icom supplies the .SCR extension if no extension is given, so it's just extra typing to add it (though it can add clarity to specify a .SCR extension). BIFs and Custom Commands are the only two places where you must specify '@' before the script name, and the reason for that is to tell Icom to run a script instead of doing what it usually Intellicomm v2.01 SCRTUTOR.DOC 9 does: send the text you define to the BBS. 1.10.3 Running Scripts from DOS Another way to run scripts is via the /scr: command line switch. Example: ICOM.EXE /scr:MENU This example above would cause Icom to switch to Terminal mode, run your MENU.SCR which we just created, display the menu (and handle any options in it, if there were real commands hooked up to the menu), then exit back to DOS as with the /run: command line switch, which does much the same thing, but for automated jobs instead of scripts. 1.10.4 Running Scripts from Scripts You can also execute a script FROM a script using the SCRIPT command. Example: SCRIPT "MENU" ;run MENU.SCR from another script print "Hello, World!" pause If you ran the above script, MENU.SCR would be executed (until completion... it could handle all sorts of different tasks) and when MENU.SCR finished, the message "Hello, World." would be displayed. (The Hello, World is simply used to show you that the original script continues execution after MENU.SCR finishes.) Again, you can add the .SCR extension if you like, but it's not necessary. Calling one script from another is not something many people will have to do, but the ability is there if needed. Note that no @ is required in either of the above examples when specifying the script name. You can also run scripts from scripts by calling up the Script Manager and allowing the user to hilight/Run one or more scripts, using the SCRIPT command but WITHOUT specifying a script filename after the command: pause "We interrupt this script to bring you the Script Manager..." SCRIPT ;the user could Tag/Run one or more scripts ; ...this script would continue below when all ; the other scripts were finished print "We now continue with our regularly scheduled program..." Note above that instead of using PRINT to print a message, and then PAUSE to wait for a keystroke, both were combined into a single PAUSE command. PAUSE accepts an optional message to PRINT before pausing. 1.10.5 Running Scripts from the Script Manager Of course, scripts can also be executed from the Script Manager by Intellicomm v2.01 SCRTUTOR.DOC 10 pressing [Alt-U] in Icom to access the Script Manager as you've just done (the Script Manager can also be used when online, by simply pressing [Alt-U] in Terminal mode... Again, it's on the [Alt-Z] terminal menu if you forget the key). You can also Tag and Run scripts one after another from the Script Manager, similar to what you can do with jobs from the Job Directory -- though this is useful only if the scripts you Tag/Run are DESIGNED to run one after the other. Further, Tagged scripts are executed in the ORDER IN WHICH THEY ARE DISPLAYED in the Script Manager, but you can easily change this order by renaming scripts (using symbols or numbers, like 1SCRIPT.SCR, 2SCRIPT.SCR, or !SCRIPT.SCR to sort to the top, etc). 1.10.6 Running Scripts via Function Keys And if the above isn't enough variety you can also "attach" scripts to function keys so a script executes when you press a key. This is best accomplished using Script Learn which asks you whether to attach the script to a function key or not. To attach a script to a key manually you must look in the Appendix of the SCRIPT.DOC manual (or in the online script help) for the "Key Code" of the function key, and must name the script using the numeric key code for the function key to attach to. Zeros must also be padded on the left side of the script name to make it exactly eight characters long. For example if you looked up the Key Code for the [F2] key you'd see that was 15360. To attach a script to the [F2] key then, you would name your script 00015360.SCR. From that point on, whenever you pressed the [F2] key from Terminal mode, 00015360.SCR would be executed. The leading zeroes MUST be added or the script will not execute when you press the key (this avoids conflicts with other scripts that just happen to use a number as the filename). Further you must use a function key (the key alone, or in combination with [Alt], [Ctrl] or [Shift] ... they all have unique Key Codes) and cannot use the [F1] key or any other keys. [F1] is reserved for online help and for future expansion. 1.11 It Can't be That Simple, Can It? Writing and using scripts can be as complicated or easy as you want it to be. There are many EXTREMELY easy-to-use script commands available to put loads of power into your hands with very little effort. To prove this point further, let's assume that you want to dial a BBS, make sure you're connected, perform a complete logon responding to every question asked by the BBS, keep an eye out for the BBS main menu so you'll know when the logon is complete, AND implement some sort of error handling so that if something goes wrong and you don't reach the main menu after, say, two minutes, you can give it up and hangup. To make it interesting, you also want to hangup if a BBS event is scheduled, and if you DO logon successfully, you want to capture BBS bulletin #5 to a file called BLT5.TXT, then logoff and hangup. If someone asked you to write a script to do this, what would you tell them? You'd probably tell them to get bent (or to use Intellicomm's built-in automation routines, which would make a lot more sense), but Intellicomm v2.01 SCRTUTOR.DOC 11 you'll be able to do this on most any BBS just a few minutes from now. It may seem a rather meaty assignment to be jumping to after "Hello, World", and with some script languages you'd be in for a rather complicated bit of script writing and concept learning to get the job done. With Intellicomm you get most of the work done with three commands: WHEN, SEND and WAITFOR. Here's the example (explanation follows the example): dial "Joe's BBS" 1 ;place the call offline goto ExitScript ;jump to label ExitScript: if not connected when "Enter Language #" send "1" when "graphics (Enter)=no?" send "N" when "st name?" send "John Smith" when "Password" send "Mypassword" when "Scan Message Base" send "N" when "More?" send "N" when "(Enter) to" send "" when "upcoming EVENT" goto HangItUp waitfor "Command? " 120 HangItUp ;the logon is now complete when ;clear all the whens, no longer needed cappush ;save capture filename/state (open/closed) capture "BLT5.TXT" ;open a new capture file send "B 5 NS" ;get bulletin 5, non-stop mode (PCBoard) waitfor "Command? " 120 HangItUp cappop ;restore the old capture file send "G" ;send [G]oodbye to logoff HangItUp: ; <-- here is where 'HangItUp' is hangup ;hangup the modem ExitScript: ; <-- here is where 'ExitScript' is exit ;end the script Just twenty lines gets the whole job done... and for demonstration purposes the above script is actually more involved than it need be. Ignore the technical details for now (you may still be wondering why there are double quotes around some items, etc.) and just take it one step at a time. The DIAL command (the first command in the script) is used to dial a BBS. The text following the dial command tells Icom which BBS to dial: in this example Icom would search your BBS Directory for a BIF with a description of "Joe's BBS", and if found it would Tag the BIF and "Dial" it. Note the '1' following "Joe's BBS". This tells DIAL that the BIF description must match exactly, and the '1' is optional. If the 1 is omitted, then any portion of any BIF description that had the text "Joe's BBS" in it ("Joe's BBS 2", etc) would also be tagged. Thus, you can also Tag/Dial multiple BIFs, depending on the descriptions you use to save your BIFs. If you had ten BIFs that had exclamation marks in their descriptions (Joe's BBS!, CRS!, Sound Advice!, etc), then you could just specify the exclamation mark, and omit the '1' following Intellicomm v2.01 SCRTUTOR.DOC 12 the description (i.e. do not force an exact match): dial "!" DIAL would then Tag/Dial all ten BIFs. When the BBS is connected to, it is untagged automatically. REDIAL can then be used to dial the tagged BBS's you haven't connected to, until all BIFs are untagged. The easiest way to find the proper text to use after the DIAL command ("Joe's BBS" above), if you intend to tag several BBS's by omitting the '1' in the DIAL command, is to enter Icom, press [Alt-D] to switch to the BBS Directory and select "Find" from the BBS Directory menu. Then enter the text you intend to use after the DIAL command ("Joe's BBS", without the quotes), select "Find all/Tag all", and Icom will show you which BIFs would be tagged if you used that text after a DIAL command. That's exactly what DIAL does: it changes to the BBS Directory, then does a "Find all/Tag all" on the text you followed the DIAL command with, then selects "Dial" from the BBS Directory menu. By using certain keywords (or exclamation points, etc.) in your BIF descriptions you can use this to your advantage to dial multiple BBS's with a single DIAL command. On to the next line: 'offline goto ExitScript'. Scripts execute from top to bottom (first line to last) unless told otherwise by specific commands: GOTO is one of those commands, and there are several others. The OFFLINE command checks the modem to see whether it's online or offline (connected or not connected). If the modem ISN'T offline (if we got connected), then Icom ignores the GOTO command and simply continues with the next line of the script. If the modem IS offline (we didn't get connected), then Icom executes the command following the offline command: GOTO in this case. I.e. an 'if' is implied before the OFFLINE command, and you can think of it as "if OFFLINE do this". GOTO causes Icom to goto (jump to) what is called a script 'label'. The label we're telling Icom to goto is label ExitScript:, which gets us down to the end of the script rather quickly (EXIT ends a script immediately). The only time you follow a label with a colon (:) is when you're actually showing Icom WHERE THE LABEL IS. I.e. where to GOTO. You don't follow labels with a colon anywhere else. I said GOTO causes Icom to jump TO the label, but that's not quite true: it jumps to the next line following the label. The label itself can't be executed, so that line is skipped and the script starts executing the line just following the label. If labels are found in the normal running of a script (we didn't GOTO the label; we just happened to run into it) the label is ignored, but any commands BELOW the label are still executed. If that's not what you want, then you simply put a GOTO above the label to to jump around the commands. For example, if the script above wasn't designed to logoff the BBS (we didn't want to hangup), we'd have to jump around the HANGUP command with a 'GOTO ExitScript' just above the label 'HangItUp:'. We could have just used 'GOTO HangItUp' in the OFFLINE command and eliminated the 'ExitScript:' label (the only place the 'ExitScript' label is used is by the OFFLINE command). But there'd be no need to hangup the modem if we were offline, so we put one label above the hangup, and can Intellicomm v2.01 SCRTUTOR.DOC 13 GOTO there to hangup and THEN exit the script, and one below the HANGUP so we can GOTO there and exit the script without hanging up. Using labels and GOTO's, etc., is how you perform decision-making in your scripts, causing some commands to execute under some conditions, and other commands (or no commands) to execute under other conditions. We also could have just used OFFLINE EXIT (if offline, exit the script... which is simpler than jumping to the label below), but two labels and a GOTO were used for demonstration purposes. The next command we run across after 'offline goto ExitScript' is the WHEN command. WHEN uses this format: WHEN "you find this text" do this ('you' referring to Icom, and 'find' meaning if the text comes in the COM port, from the BBS.) WHEN doesn't actually do anything on its own, unless you specify it all by itself, with no parameters following it, in which case it CLEARS all the WHENs defined previously. It's not until WAITFOR is executed that the WHENs become active: WHEN and WAITFOR works as a team. WHEN simply causes Icom to store the text and position of the command following the WHEN in memory, for later use with WAITFOR. WAITFOR activates all the WHENs (all prompts are then watched for simultaneously... you can use up to 19 WHENs at a time) while WAITingFOR specific text from the BBS. Waitfor uses this format: WAITFOR "wait for this text"