> Tutorial
A function performs a task, such as a calculation or an action. It takes arguments as input, runs instructions and can return a result.
In our current code, we use the following functions and methods:
me.setWeapon(weapon): it has 1 parameter and returns nothing.Fight.getNearestEnemy() → enemy: it has 0 parameters and returns the nearest enemy.me.moveToward(target) → mp: it has 1 parameter and returns the number of MP used.me.useWeapon(target) → success: it has 1 parameter, uses your weapon on someone and returns the result of the attack.Leek Wars provides hundreds of functions and methods, gathered on a single page: the documentation. To open it, go to the Help tab, then click Documentation.
You can open the documentation from any page with the Ctrl + Alt + H shortcut. Try it now!
The description of a function gives you the following information:
Now that we're familiar with functions, let's use a few more of them in our AI!
A chip is a power you can use in a fight to heal, protect or boost yourself, attack and more. To use one, you first need to equip it on your leek:
Then, use the me.useChip(chip) method to cast a chip. Unlike weapons, chips don't need to be equipped beforehand in your code.
Buy the Bandage, Motivation, Protein and Helmet chips and equip them on your leek.
We'll use all of them at the start of our turn, by adding the following code after equipping our weapon:
Chip.motivation, Chip.protein are, like Weapon.pistol, predefined values that represent the chip or weapon we want to use. They're listed in the documentation, just like functions.
What can a function do?
Calculate and return a value Perform an action or run instructions Return no value Take several parameters
Impossible de charger les données du jeu.
Vérifiez votre connexion et réessayez.