> LeekScript Tutorial
This article is based on knowledge of Les_Expressions, Les_Variables, and Les_Functions. It only aims to offer one more tool for problem solving. Due to the fact that leekscript does not have native annotation tools (like most dynamically typed languages), each person will tend to have their own syntax.
As a reminder, objects are simply something that can be manipulated by the language, we can assign them to variables, pass them as arguments, give them to function returns, and use them in expressions. In leekscript we have access to the following basic objects:
As you can see, these objects have been collected in a not insignificant way. Each object is part of a family, which we will call type.
Each object therefore has a type, and in order to be able to reason with it, we will need a way to write them. We will use within the framework of this article the following notation: object: Type, the name of the type beginning with a capital letter. You are free to use another scoring system. Here is the list of the most basic types, along with some possible values:
null : Null true, false : Bool 1, -273: Int 1.0, 2.34: Float "a", "abc": String
The names used here are arbitrary. This is not a convention used by the Leek Wars community. It is also possible to group the objects included in Int and Float in the same category Num because it is very rare to have to do the distinction when we handle them.
Be careful, the Leekscript does not support type annotation, you will just have to comment them out if you want to keep track of them.
// object: Type object; object; // : Kind
This notation is used to be able to represent the possibility that an object has any type. It is noted in the same way, but with a lowercase letter at the beginning of the name. object: a, here we don't know what type of object is. It can be anything. If we define otherObject: b, we also don't know what its type is, it can even be of the same type as object. However, if we set sameObject: a, we get a bit more information. We still don't know what the exact type of sameObject is, but we do know that it is the same as object. For example, if object: Num then sameObject is also of type Num. otherObject could be of type Num, but it could also be of type String or Bool, etc. .
These are slightly more complex types. You must have wondered why arrays and functions were not presented earlier. We can say, in a way, that they contain other types. For example [1] contains Num, function(x) { return "" + x; } takes anything (a) and returns it as a string (String).
To annotate these Types, we use a concrete type, followed by other concrete or variable types. For example, for an array of numbers, we can annotate it like this: array: Array Num, and for an array of strings: array: Array String . The function that took any object and returned its representation as a string can be annotated: toString: Function a String. It is therefore possible to have several types as arguments. Another example is associative arrays. For example, an associative array that indicates whether cells are out of sight of an adversary, can be annotated: safeCells: Assoc Cell Bool.
In the future, when we write down arrays or functions, we will use a lighter syntax:
array: [Num] toString: a->String safeCells: {Cell: Bool}
In the case of functions that do not take an argument, we will use (). It is possible to use it in principle in the return of functions, but any function that does not return anything, implicitly returns null in Leekscript. For example, rand: () -> Float, say: String -> () or say
Impossible de charger les données du jeu.
Vérifiez votre connexion et réessayez.