> Tutorial
A list lets you 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 working with lists. The most notable ones 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 in a list: the for in loop. The following code does the same as the previous one, but more concisely:
Our current AI has a problem: when the enemy is almost dead, our leek uses its boosts, heals and shields before using its weapon, when it could have finished the enemy off!
To improve this end-of-fight situation, we'll estimate the damage we can deal to the enemy, to know whether we can finish it off.
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 damage:
We add the damage to the total:
We finish with a condition: if the total damage is greater than the enemy's life, we're going to kill it, so we attack! Otherwise, we hold back and use chips:
> Tip: you can extract a range from a list with my_list[2:8].
> Tip: lists can be nested: a list inside a list [ [1, 2, 3] ], and you can access a list inside a list: my_list[0][0].
What can a list be used for?
Storing several values Sorting values Running instructions in parallel Performing several calculations
Which pieces of code are valid?
a = [1, 2, 3] a[0] + a[2] [1, 2, 3] = a len([1, 2, 3]) [ [1, 2], [3, 4], [5, 6] ] my_list[5][10]
Impossible de charger les données du jeu.
Vérifiez votre connexion et réessayez.