Skip to content
ChartDeck ChartScript docs Account Open the terminal

CS2701

error A condition must be a bool, but this is got.

#What it means

The condition of an if, a while, a ?: or a switch case must be a bool (true or false). This one has another type, shown in the message.

#Typical cause

  • A string or a colour used as a condition.
  • A comparison left unfinished, as in if mode instead of if mode == "up".

#How to fix it

Compare the value with something to get a bool. See Conditionals.

#Example

ChartScriptError: CS2701
//@chartscript 1
indicator("Mode")
const mode = input.string("up", "Mode", { options: ["up", "down"] })
let level = 0
if (mode) {
    level = 1
}
plot(level)

Fixed

ChartScriptOpen in editor
//@chartscript 1
indicator("Mode")
const mode = input.string("up", "Mode", { options: ["up", "down"] })
let level = 0
if (mode == "up") {
    level = 1
}
plot(level)
  • CS2204 — A condition cannot be na; write: example
  • CS2714 — A check must be a bool, but this is got.

The ChartScript documentation is in English for now; translations will follow.