> Tutorial
You've seen that you can work with numbers, but there are also special values: None and booleans.
None valueNone is a value that represents an empty or invalid value, or even an error, but it's different from the number 0.
For example, me.weapon returns the weapon your leek is holding, or None if you have no weapon in hand.
You may have noticed that me.setWeapon() costs 1 TP per turn. You can limit its use to turn 1 with this condition:
if me.weapon is None:
me.setWeapon(Weapon.pistol)
You test for a None value with is None (and is not None for the opposite).
True and FalseBooleans are two values: True and False. They can be used to represent anything that can have two states, such as:
a = True
b = False
Examples of properties and methods that return a boolean:
enemy.alive returns True if the entity is alive, False otherwise.me.canUseWeapon(enemy) returns True if you can use your weapon on the enemy.Example: we check whether we can use our weapon on the enemy:
if me.canUseWeapon(enemy):
# we can use our weapon on the enemy
pass
What can None be used for?
Representing missing information or a missing value Representing the number 0 Representing an error Representing a poor-quality program
What are booleans used for?
Representing a value with two possible states Representing a very large value
me = Fight.me
# We take the pistol if it is not equipped
if me.weapon is None:
me.setWeapon(Weapon.pistol)
# We get the nearest enemy
enemy = Fight.getNearestEnemy()
# We move toward the enemy
me.moveToward(enemy)
# Boosts, shield and heal
me.useChip(Chip.motivation)
me.useChip(Chip.protein)
me.useChip(Chip.helmet)
# We heal ourselves if our life is below our max life.
if me.life < me.maxLife:
me.useChip(Chip.bandage)
# We try to shoot at it!
me.useWeapon(enemy)
Impossible de charger les données du jeu.
Vérifiez votre connexion et réessayez.