ScratchScript Why use Scratch from an easy Drag-and-Drop Interface when you can use a cumbersome and cryptic typed interface? Introduction ============ ScratchScript is a small scripting language that runs in Scratch. It uses a list as the "input file". It was written for fun and to provide another way to interface with Scratch. A single sprite is controlled by commands entered into the "User Input" list. The syntax is very finicky, mostly due to the very limited text processing capabilities of Scratch. Because of the limitations of Scratch, all commands must be entered with no leading or trailing spaces! For the commands that take parameters (arguments), each parameter must be entered on it's own line. Some commands allow an unlimited list of parameters (X and Y data, for instance). For these types of commands, the end of the input is marked by a single "#" character with no leading or trailing spaces. ScratchScript allows user defined macros. These can be defined in the usual input list, "User Input", or they can be added to a list of permanent built in macros, called "Built In Includes". In either location, a string made up of three pound signs "###" is used to separate the definition from other data. Again, no leading or trailing spaces are tolerated. Credits ======= Thanks to the Scratch Team for the great job putting Lists in Scratch! Thanks to Jens for showing us all the way. And thanks to likegames for inspiration and encouragement. Motion Commands =============== GOTO - cartisian coordinate absolute motion x y ... (more X/Y pairs of data, if desired) # (be sure to put this end of data character after the last X/Y pair) ORIGIN - set the origin that will be used for subsequent relative position commands (GOTOR,STRINGR,POSR) to the current position of the sprite GOTOR - cartisian coordinate relative motion. All motion is relative to position of last ORIGIN call x y ... (more X/Y pairs of data, if desired) # (be sure to put this end of data character after the last X/Y pair) POS - reposition to an absolute position. Does a single penup move. No scaling is applied. x y POSDELTA - reposition by a change in X and Y. Does a single penup move. No scaling is applied. x y POSR - reposition to a relative position, set by the last ORIGIN call. Does a single penup move. Scaled. x y Notes on GOTO,ORIGIN,GOTOR,POS,POSDELTA,POSR If you just want to work with screen coordinates, use POS and POSDELTA to position the pen and GOTO to draw lines (preceeded by a PENDOWN command). If you want to build an image that can be drawn from the current mouse position and scaled using the SCALE command, use ORIGIN to set the origin to the mouse position, then use POSR to position the pen relative to the new origin. Then, use GOTOR to draw lines (preceeded by a PENDOWN command). Most of the other geometry comamnds (SQUARE, CIRCLE, LINE, VLINE, CROSS) that allow you to enter dimensions work well for this sort of image construction as well. Macro geometry commands (STAR, FRAME, STAR2, HOUSE) may not work as well. GLIDE - glide to an absolute position in a given amount of time glide time x y GLIDER - glide to a relative position, set by the last ORIGIN call, in a given amount of time glide time x y TURNMOVE - polar coordinate relative motion angle distance ... (more ang/distance pairs of data if desired) # (be sure to put this end of data character after the last X/Y pair) POINTANGLE - Point in the specified direction direction SCALE - specify the Scale factor to be applied to all motion commands (except POS and POSDELTA) scale factor SPIN - spin the sprite clockwise using 45 degree increments - uses the SPIN_INC built-in macro HOME - raise the pen and bring the sprite to 0,0 and pointed to the right - uses the HOME_INC built-in STAR - draws a string art star - uses the STAR_INC built-in FRAME - draws a string art frame - uses the FRAME_INC built-in HOUSE - draws a simple outline of a house - uses the HOUSE_INC built-in SQUARE - draws a square centered on the current postion with given side length side length RECTANGLE - draws a rectangle centered on the current position with given length and height length height CROSS - draws a cross centered on the current position with given side length side length LINE - draws a horizontal line centered on the current position with given length length VLINE - draws a vertical line centered on the current postion with given length CIRCLE - draws a circle of given diameter centered around the current position diameter ARC - draws a CW circular arc of given radius centered around the current position starting at the given start angle and proceeding for the specified number of degrees diameter start angle degrees of arc SINE - draws a plot of a sine wave of given amplitude, overall length and number of cycles. Use the VSINE command if you want a sine wave running vertically amplitude length cycles COSINE - draws a plot of a cosine wave of given amplitude, overall length and number of cycles. Use the VCOSINE command if you want a cosine wave running vertically amplitude length cycles STRING - draws string art between the x/y pairs using the specified number of division. Needs at least three points to work. number of divisions (10 makes a good starting value) x y x2 y2 x3 y3 ....(more x/y pairs, if desired) # (be sure to put this end of data character after the last X/Y pair) STRINGR - draws string art like STRING but all motion is relative to the origin set by ORIGIN number of divisions (10 makes a good starting value) x y x2 y2 x3 y3 ....(more x/y pairs, if desired) # (be sure to put this end of data character after the last X/Y pair) Pen Commands ============ PENUP - raise the pen PENDOWN - lower the pen PENCOLOR - specify the pen color using one of the values below red,green,blue,yellow,orange,aqua,purple,violet,black PENCOLORCHANGE - the amount the pen color will change between lines when doing string art amount (10 works nicely) PENSIZE - set the pen size size STAMP - stamp the current costume CLEAR - clear the screen of pen markings and stamps Sprite Appearance Commands ========================== HIDE - hide the sprite SHOW - show the sprite COSTUME - change the costume to the specified name or number costume name or number SIZE - set the sprite size percentage of full size BACKGROUND - set the background to the specified name or number background name or number SAY - display one lines of text in a speech bubble for the specified amount of time display seconds stuff to say Other Commands ============== CALC - calculate an operation on a list of numbers using any or the operators +-*/ operator (+-*/) number number .... (more numbers, if desired) # (be sure to put this end of data character after the last number) WAIT - pause operation for a specified number of seconds wait time COMMENT - one or more lines of comment text comment .... (more comment lines, if desired) # (be sure to put this end of data character after the last comment line) SLEEP - puts the cat to sleep WAKEUP - wakes the cat up COOKIE - the cat will tell you a fortune cookie sayingclear glide 2 0 -40 stamp hide include rainbow show wait 2 cookie clear glide 2 -200 -40 TEXT - prints text (one letter at a time) using stamping. Size is set with the SCALE command first letter second letter .... (more letters, if desired) # (be sure to put this character after the last letter) Notes on TEXT: Only a very limited character set is recognized A-Z and 0-9 plus a few other characters. The following characters confuse the list used to input stuff and need to be entered as words: DOT - period or decimal point PLUS - Plus sign MINUS - Minus Since putting in a space is easy to mess up by putting in two or three...I decided if you wanted a space you would input an underscore character for the space. Macro Commands ============== DEFINE - define a set of commands at runtime to be stored and invoked later with an INCLUDE command macro name command .... (more commands, if desired) ### (be sure to put this end of definition string after the last command) INCLUDE - request that a stored macro be retrieved and executed. Could be a Built-in or runtime macro macro name Notes about Macros ================== Note that if you decide to add macros to the Built-in list (called "Built In Includes") you don't need a DEFINE command (since the list contains only macros) but you do need the ### separater between macros. Note that Built-in macros have priority over runtime defined macros, if they have the same name. Be sure to click on the Green Flag after adding built-ins so that the index is rebuilt. A macro can reference other macros with the INCLUDE command to any desired level. The macro is simply copied to the input list for processing, the pointer adjusted and processing continues. Some commands actually invoke built-in macros themselves. Macros used by commands are named the same as the command but with a suffix of "_INC". These commands will execute fairly slowly but have the advantage of being easy to change.