Conditions (Python)

Conditions

> Tutorial

In the previous chapter, we saw how to boost yourself, give yourself a shield and heal yourself. You've probably noticed that boosting and protecting yourself is always useful, but healing does nothing when your life is already at its maximum.

To avoid casting a heal and wasting TP , we'll use a condition, written like this:

if me.life < me.maxLife:
	me.useChip(Chip.bandage)

This code casts the Bandage only if we're injured, that is, when our current life me.life is less than (` Which code(s) are valid?

if (me.life &lt; me.maxLife) { me.useChip(Chip.bandage) } if me.life &lt; me.maxLife me.useChip(Chip.bandage) if me.life &lt; me.maxLife: me.useChip(Chip.bandage) else: me.useChip(Chip.helmet) if me.life &lt; me.maxLife: me.useChip(Chip.bandage)

Full AI

me = Fight.me

# We take the pistol
me.setWeapon(Weapon.pistol)  # Careful: this costs 1 TP

# 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)