> Tutorial
A function carries out 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!
A function's description gives you the following information:
Now that we're familiar with functions, let's use a few more 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 in your code before you use them.
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 and Chip.protein are, like Weapon.pistol, predefined values representing the chip or weapon you want to use. They're listed in the documentation, just like the functions.
What can a function do?
Calculate and return a value Perform an action or run instructions Return no value at all Take several parameters
Impossible de charger les données du jeu.
Vérifiez votre connexion et réessayez.