> LeekScript
LeekScript 4 is the fourth version of the LeekScript language, released on July 1, 2022. This page summarizes all the new features brought by this version.
In LeekScript versions 1 to 3, arrays were both lists ([1, 2, 3, 4]) and associative tables (['a': 5, 'b': 12]) . As of LeekScript 4, the two aspects are separated into two different types: lists (Array) and tables (Map). These two new types are more efficient than the old common type, and give greater clarity in use.
An Array list is a continuous sequence of elements, starting at index 0. They are equivalent to ArrayList of Java or vector of C++. You can quickly access an element with its position, insert/delete an element at any position.
array[10] = v.Map).Array type uses all the functions of the "List" category of the documentation.A Map table is an object that relates a key to a value. They are equivalent to HashMap of Java or unordered_map of C++, the pairs of (key, value) are not ordered. Keys can be of any type: number (integer or real), character string, object, etc. We can quickly retrieve a value associated with a given key. This new type replaces the "associative" aspect of the old arrays
Map uses all the functions of the "Table" category of the documentation, prefixed by "map".[:]new Map()arraySome(list, predicate): returns true if predicate returns true for at least one element of the list.arrayEvery(list, predicate): returns true if predicate returns true for all elements of the list.removeAll(list, element): removes all "element" elements from the list.arrayFrequencies(list): returns a table associating (element => quantity).arrayChunk(list, size): returns a list containing sub-lists of size N.arrayUnique(list): returns a new array without duplicates.arrayRandom(list, n): returns a list of N random elements.The new arrays and maps being much more efficient and light in operations, it was necessary to reestablish a limit at the level of the RAM (working memory of the program). Indeed, with very little operation it is possible to fill gigabytes of RAM easily.
The RAM limit is set at 60MB for each AI (entity + summons) per fight, which corresponds to 7,500,000 list, table or object items. This limit is effective in LS4 because the old tables do not use this RAM system, they do not need it because their operation consumption is large enough.
The getMaxRAM() and getUsedRAM() functions are added to monitor its RAM consumption in real time.
Integers are now represented on 64 bits instead of 32 before (in all versions of LeekScript). The increase allows to do calculations with larger numbers and allows to have more bits for binary manipulations.
The "Arrow function" syntax is now available to write anonymous functions more simply:
In constructors, methods and static methods, it is now possible to use default values for each parameter:
Two new possibilities are added to access lists:
list[-1] returns the last, list[-2] returns the penultimate.list[10:20] returns a new list containing the elements from position 10 to 20 (exclusive).list[10:20:3] returns the elements at position 10, 13, 16, 19.list[20:10:-3] returns the elements at position 20, 17, 14, 11arraySlice(start, end, increment) function which replaces subArray has the same behavior as the list[start:end:increment] syntax.The old == operator, which did some exotic equality checking like 1 == true. The potentially confusing 12 == [12] is removed in LS4, and replaced with ===, which performs a strict equality comparison. You must therefore write == instead of ===.
Be careful when replacing some of your == by ===, it is possible that the == made a comparison with numbers and/or booleans and/or null.
It is possible to write numbers in hexadecimal and binary form, in addition to decimal:
var a=0xabcdef // 11259375 var b=0b110110101 // 437
It is possible to write long numeric constants with underscore "_" separators, example:
var one_billion = 1_000_000_000
In the arrayMap, arrayFilter, arrayIter, arrayPartition, arrayFoldLeft/Right functions, the callback functions take the arguments (value, key/index) always in this order. The order was (key, value) and (value) previously.
Moreover, all these functions take as 3rd parameter the array being traversed.
It is therefore possible to pass any number of arguments to a callback, the missing values being replaced by null.
end position of the subArray function is now exclusive to LS4+.removeElement function no longer leaves holes in LS4+.arrayFlatten function no longer copies elements.assocReverse, assocSort, keySort functions are removed and removeKey is replaced by mapRemove in LS4+.arrayMin cost.randFloat is renamed to randReal.All functions in the game have been precisely typed, which allows errors to be added when a parameter is incompatible with the expected type of a function.
Since type inference is still very basic and destined to evolve, these type errors are for the moment warnings.
It is now possible to write a = b = c without parentheses.
When declaring a table, an error (LS4+) or a warning is returned if a key appears twice:
The complexity of each function is displayed in the documentation.
The JSON functions jsonEncode and jsonDecode now handle new lists and objects:
jsonDecode("[1, 2, 3]"): returns a new list jsonEncode("{a: 2, b: 4}") / jsonDecode("{a:2,b:4}"): works with objects.
bitCount(x): returns the number of bits at 1 in the number.trailingZeros(x): returns the number of bits at 0 at the end of the number.leadingZeros(x): returns the number of bits at 0 at the beginning of the number.bitReverse(x): returns a new number with all bits reversed from left to right.byteReverse(x): returns a new number with all bytes (group of 8 bits) reversed from left to right.rotateLeft(x, y): returns a new number with the bits shifted from y to the left (resets the bits to the right).rotateRight(x, y): returns a new number with the bits shifted from y to the right (resets the bits to the left).hexString(x): returns a string representing the number in hexadecimal.binString(x): returns a string representing the number in binary.realBits(x): returns the bits of the number as an integer.isFinite(x): determines if the number x is finite.isInfinite(x): determines if the number x is infinite.isNaN(x): determines if the number x is a NaN value.isPermutation(x, y): returns true if the number x is a permutation of the number y.NaN: Constant representing a NaN value. We have X == NaN equal false all the time (hence the isNaN function).Infinity: Constant representing infinity. To have its opposite, use -Infinity.Integer.MIN_VALUE and Integer.MAX_VALUE: minimum integer (-2^64 = 9223372036854775808) and maximum (2^63-1 = 9223372036854775807)Real.MIN_VALUE and Real.MAX_VALUE: real minimum (2.2250738585072014e-308) and maximum (1.7976931348623157e308)final keyword for class fieldsIt is possible to use the final keyword in front of a class field to indicate that this field is no longer assignable after the construction of the object. An assignment is the use of the = operator, it is always possible to modify the content of the field if it is of the object or list type, for example. For an array-type final field, you must therefore use arrayClear(object.field) instead of object.field = [].
\ and \=The \ and \= operators are added to perform integer or Euclidean division, for example:
Note that both numbers are converted to integers if they are not already integers:
debug([10, "20", "hi"]) returns [10, "20", "hi"] instead of [10, 20, hi].break and continue inside a function and outside the loop.A['m'] and var m = A.m.Impossible de charger les données du jeu.
Vérifiez votre connexion et réessayez.