Livecode Wiki

Expect Precondition With Reason[]

Use this statement at the start of a handler to check that necessary preconditions for the handler are satisfied. For example, the handler may require that its parameters have a particular structure or fall within a particular range, or may need the system to be in a specific state.

If the condition is false, an error will be thrown including the Reason for the check.


-- Draw a random variate from the Bernoulli distribution with
-- parameter pParam.  A Bernoulli variate may be 0 or 1; the
-- parameter pParam is the probability that the result is 1.
handler BernoulliVariate(in pParam as Number) returns Number
  expect (pParam >= 0 and pParam <= 1) because "Bernoulli parameter must be a probability in [0,1]"
  if (any number <= pParam) then
     return 1
     return 0
  end if
end handler