Difference between revisions of "A few basic examples"

From Remeis-Wiki
Jump to navigation Jump to search
Line 21: Line 21:
 
  x = 7.5;
 
  x = 7.5;
  
Above, the first line defines an empty variable that does not yet have a type. The second line assigns this variable a value, 7.5, and automatically assigns it a corresponding type. In this case a double.
+
Above, the first line defines an empty variable that does not yet have a type. The second line assigns this variable a value, 7.5, and automatically assigns it a corresponding type. In this case a double. A variable does not have to be a number:
 +
 
 +
variable y;
 +
y = "hello";
 +
 
 +
creates a variable y and assigns it to the string "hello".
 +
 
  
 
You can also define a variable and make it equal something in one go:
 
You can also define a variable and make it equal something in one go:
  
 
  variable x = 7.5;
 
  variable x = 7.5;
 +
variable y = "hello";

Revision as of 09:30, 21 January 2020


This page is intended to give a few examples for students (mainly students working with Victoria, but the rest is welcome to use it!), who have little to no coding background.

A good convention is to always use filenames that end in .sl for your scripts. You can then run the script using isis filename.sl from the console. Always end your script with exit; so that it exists once it has finished running.

Let's write a simple scripts that says "hello world"!

print("hello world");
exit;

You can get more information on any command by starting isis (just type isis in the console) and entering help commandname, e.g., help print.

Now that we said hello to the world, we'll address some maths first.

Define a variable x that equals 7.5:

variable x;
x = 7.5;

Above, the first line defines an empty variable that does not yet have a type. The second line assigns this variable a value, 7.5, and automatically assigns it a corresponding type. In this case a double. A variable does not have to be a number:

variable y;
y = "hello";

creates a variable y and assigns it to the string "hello".


You can also define a variable and make it equal something in one go:

variable x = 7.5;
variable y = "hello";