Standard functions (Python)

Standard functions

> 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:

The documentation

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:

Using chips

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.

❓ Quiz

What can a function do?

Calculate and return a value Perform an action or run instructions Return no value at all Take several parameters

Full AI