Sampi

Home Older Versions Documentation Changelog Learn


Variables

This creates a variable.


set x to 1
say(x)
        

A variable is like a box that stores a value. Right now, there is a box called x with the value 1 in it. You can change variables too.


set x to 1
say(x)
set x to x + 1
say(x)
        

When naming a variable in Sampi, there are some rules. It can use only lower case letters, upper case letters, numbers, and underscores (_). It cannot be one of Sampi's keywords. Keywords are just special words that do things. When naming a variable in Sampi, we ask you to use snake_case. That is when you use underscores instead of spaces, like player_x.


Glue

Sometimes when making a variable, you don't want it to change. It is not really a variable if it can't change, but it is useful for stuff like constants (pi, e) and the name of a player. This is when you use the glue keyword. The glue keyword means you can't change its value.


glue pi to 3.14
        

Glueing variables has some rules. Once a value is glued it can never be changed. Also, you cannot glue a variable that has already been created.


Comments

These are not variables, but are very useful to have. Commets are ignored while running, and can be used to document code. Commets are made with //.


// create variable pi
glue pi to 3.14
        

There are also block comments, which can span multiple lines. Block commenst are made with #.


# this code is to set up all the constants.
these will be used later in the program #

glue pi to 3.14
glue phi to 1.61
glue e to 2.71
        

Comments can also be used to stop code from running during testing.


set player_x to 1

#
set player x to player_x + 1
say("hello")
#

say(player_x)
        

Next