> Tutorial
You've seen that you can work with numbers, but LeekScript also has special values: null and booleans.
null valuenull is a value that represents an empty or invalid value, or even an error, but it's different from the number 0.
For example, the getWeapon() function returns the weapon your leek is holding, or null if you don't have a weapon in your hands.
You may have noticed that setWeapon() costs 1 TP per turn. You can limit its use to turn 1 with this condition:
if (getWeapon() == null) {
setWeapon(WEAPON_PISTOL)
}
true and falseBooleans are two values: true and false. You can use them to represent anything that has two states, such as:
var a = true
var b = false
Examples of functions that use booleans:
true if the chip needs a line of sight, false otherwise (like the Spark chip).true if the entity is alive and false otherwise.Example: checking whether a chip needs a line of sight:
if (chipNeedLos(chip) == true) {
// the chip needs a line of sight
}
What can null be used for?
Representing a lack of information/value Representing the number 0 Representing an error Representing a poorly written program
What are booleans used for?
Representing a value with two possible states Representing a very large value
// Equip the pistol if it isn't equipped yet
if (getWeapon() == null) {
setWeapon(WEAPON_PISTOL)
}
// Get the nearest enemy
var enemy = getNearestEnemy()
// Move toward the enemy
moveToward(enemy)
// Boosts, shield and heal
useChip(CHIP_MOTIVATION)
useChip(CHIP_PROTEIN)
useChip(CHIP_HELMET)
// Heal ourselves if our life is below our max life
if (getLife() < getTotalLife()) {
useChip(CHIP_BANDAGE)
}
// Try to shoot it!
useWeapon(enemy)
Impossible de charger les données du jeu.
Vérifiez votre connexion et réessayez.