> Tutorial
A list is used to store several values in a specific order.
You can create a list with the following syntax:
The first position in a list is position 0. You access a specific element of the list with:
Many operations are available for handling lists. The most notable are:
for in loopYou can iterate over each of the values in a list using a for loop with range, like this:
But there is a simpler way to iterate over each of the values of a list, the for in loop. The following code is equivalent to the previous one but is more concise:
Our current AI has a problem: when the enemy is almost dead, our leek will use its boosts, heals and shields before using its weapon, when it could have finished the enemy!
To improve this situation at the end of the fight, we will estimate the damage that we can inflict on the enemy to know if we can finish it.
We start by getting the list of our weapon's features with me.weapon.features:
Each feature has properties: .type (the effect type), .minValue (minimum value), .maxValue (maximum value)... We calculate the final damage when the feature is a damage:
Add the damage to the total:
We end with a condition: if the total damage is greater than the life of the enemy, we will kill him: we attack! Otherwise, we wait with chips:
> Tip: you can extract a range of a list with numbers[2:8].
> Tip: you can nest lists: a list inside a list [ [1, 2, 3] ], and access a list inside a list: numbers[0][0].
What is a list for?
Store multiple values Sort values Execute instructions in parallel Perform multiple calculations
Which codes are valid?
a = [1, 2, 3] a[0] + a[2] [1, 2, 3] = a len([1, 2, 3]) [ [1, 2], [3, 4], [5, 6] ] numbers[5][10]
Impossible de charger les données du jeu.
Vérifiez votre connexion et réessayez.