Skip to content

Getting Started

AdeogunTechno edited this page May 19, 2025 · 10 revisions

Getting Started with AmberScript

AmberScript is a fairly simple language created to run in Scratch.

Its general syntax is mycommand myargument "My Argument with Spaces"


Creating an Example Space

To start, lets create a simple script:

Try entering

render.new myobject1 test 0 0

and run the code.

Do you see anything?
No. That's because the Object is hidden by default.

Modify its visibility by adding

render.modify myobject1 sprite.visible true

and run your code again.

Cool! Now we can see the sprite on our screen at coordinates (0, 0).


Working With Functions

Now, say we want to make it easier to create a new Object (A.K.A Clone) that is visible by default.
Have any ideas?

We use functions, of course!


Functions are like templates; they save us from having to rewrite the same chunk of code over and over again.

Their function (no pun intended) is akin to that of Scratch's Custom Blocks or Java and Python's Functions.


Let's create, or register, a new function for creating visible objects.

function.register new_visible_object "..."

This registers a new blank function called "new_visible_object".


Cool! So now we've got a blank function.
A function's code has to be written in one long string, separated by the delimiter "\\n"

Note: We write "\\n" instead of "\n" because the parser automatically escapes the first \ before running the function.

So, the code we want the function to run would be

render.new myobject1 test 0 0\\nrender.modify myobject1 sprite.visible true

(Note our use of the delimiter "\\n")


Once we add it to our function, we get

function.register new_visible_object "render.new myobject1 test 0 0\\crender.modify myobject1 sprite.visible true"

Add this code to a new space, and add

! new_visible_object

to actually call the function. Now run your code!


Yes! Now we have a reusable function!


Going Further With Functions

If you're an experienced programmer, you may know that our function isn't very reusable.
Since the Object Identifier, "myobject1", is hardcoded, that's all our function can generate.


A function's arguments are stored in the format $f(x), where x is the argument's number.
In our case, we only need one argument (to replace myobject1), so we'll use the function's first argument, $f(1).


Ok, so let's replace any mention of myobject1 within our function with $f(1).

function.register new_visible_object "render.new $f(1) test 0 0\\crender.modify $f(1) sprite.visible true"`

Great! So now we call the function with its argument. ''' ! new_visible_object myobject1 '''


This gives us the same result as before, but now we can change the object identifier to whatever we want!

By now, you've probably seen that the syntax for variables (and most built-in functions) is $x(y,z).
X indicates the variable type (in our case f for function), and y and z are the arguments we pass in.

AmberScript is full of possibilities and features plenty of interesting functions. We invite you to try them all out!

Clone this wiki locally