Method works in REPL; can't use in a function body

It is hard to debug this without an MWE.

There is probably a global variable that does not have the value you think it has. Try to write cleaner code, passing all arguments needed to a function — eg infectious for spread.

4 Likes