Eng:Scratch File Format (1.4)/Scripts

From a [ post] by nXIII:

all scripts are converted to tuples before they are saved; each stack is converted to: (where indicates an array)

(position (block1 block2 block3 ...))

each block is converted to:

(selector arg1 arg2 arg3 ...)

if the argument is a number, string, boolean, or color it is just included as the (n+1)th member of the array. If it is a block, the block is converted to a tuple and included in the correct place.

For example, the script: when I receive [message v] set [var v] to ([sqrt v] of (100)) repeat until <(var)=[1]> wait ((3) - (2)) secs change [var v] by (-1) end say (join [hello ] [world]) if < or > broadcast [message v]	switch to costume [costume1 v] end

Gets encoded something like this: (       Point(20, 20.0),         [            [<#EventHatMorph>, 'message'],            [<#changeVariable>, 'var', <#setVar:to:>, [<#computeFunction:of:>, 'sqrt', 100]],             [<#doUntil>, [<#=>, [<#readVariable>, 'var'], '1'],                 [                    [<#wait:elapsed:from:>, [<#->, 3, 2]],                     [<#changeVariable>, 'var', <#changeVar:by:>, -1]                ]            ],             [<#say:>, [<#concatenate:with:>, 'hello ', 'world']],             [<#doIf>,                [<#|>, [<#touching:>, ], [<#keyPressed:>, 'space']],                 [                    [<#broadcast:>, 'message'],                     [<#lookLike:>, 'costume1']                ]            ]        ]    )

Where <#say:> represents the Squeak Symbol "say:", and [] is used interchangeably with for tuples. (Whitespace added for clarity.)