---
title: "Script errors and troubleshooting"
description: "Fix TapHome script errors: Line in script: 1 Message: Division by zero, Unknown variable or constant, Wrong number of literals and operators, PARSETEXT out of range, function not supported here."
url: "https://taphome.com/en/docs/script/errors/"
language: en
lastmod: 2026-10-26
generator: hugo
ai:
  topics: ["scripting-language","script-errors","troubleshooting","division-by-zero"]
  questions: ["How do I fix the \"Line in script: 1 Message: Division by zero\" error in a TapHome script?","How do I divide two variables (va1/va2) safely, applying the formula only when the denominator is greater than 0?","What does \"Unknown variable or constant\" mean in a TapHome script?","Why does \"1 == 1\" give \"Wrong number of literals and operators in expression\"?","Why does PARSETEXT stop the script with \"Specified argument was out of the range of valid values.\"?","Why do I get \"ADDERROR function not supported here.\"?","What does \"Please update your core unit to be able to use this feature\" mean?","How are run-time errors of a TapHome script reported?"]
---

# Script errors and troubleshooting

TapHome script error messages quoted verbatim — Division by zero, parse errors, run-time errors and context or version errors — with the cause and the fix of each.

Last updated: 2026-10-26

A TapHome script fails in one of two ways. A **parse error** is found while the text of the script is read: the script editor shows it and the script does not run. A **run-time error** stops a script that is already running. The messages below are quoted verbatim; `X`, `A`, `B` and `N` stand for the name, type or number in the message.

## How errors are reported

A run-time error carries the line of the script and the message:

```text
Line in script: 7
Message: Division by zero
```

Where the line break is not shown, the same error reads `Line in script: 7 Message: Division by zero`. A script stopped by a run-time error gives no value (`Null`); a Formula smart rule then also has `LastState` = `Null` on its next run.

## Division by zero

`Line in script: 1 Message: Division by zero` means that a divisor was exactly 0 when the script ran — typically a device value, such as `va2` in `va1/va2`. Divide only when the divisor is greater than 0:

```taphome
IF(va2 > 0, va1/va2, 0);
# Result: 0 when va2 is 0, otherwise va1 divided by va2
```

The function form of `IF` evaluates only the chosen branch, so it never divides by 0. Use `va2 <> 0` when the divisor can be negative. More recipes in [Examples](https://taphome.com/en/docs/script/examples/#safe-division).

## Parse errors

| Message | Cause and fix |
|---|---|
| `Unknown variable or constant 'X'` | A typo, a device value not added to the script, or a word the language does not have: `NOT 1` gives `'NOT'` — negation is `!`. Outside a block a missing `;` on the previous line can show up as the next name. |
| `Unknown function 'X'` | No such function. `MODBUS`, `TOBYTEARRAY` and `BYTEARRAY` do not exist — use `MODBUSR` or `MODBUSW`, `TOBYTES` and `BYTECOLLECTION`. |
| `Wrong number of literals and operators in expression` | An operator without an operand, for example `1 == 1`. Equality is `=`, inequality `<>`. |
| `Unexpected character 'X' at the end of statement.` | The `;` before the next statement is missing. Inside a block the message ends with `Expected ';'`, for example `Unexpected character 'E' at the end of statement. Expected ';'` before `END`. |
| `Unexpected character '.'` | A property read from a function result, such as `AVG(1, 2).Type`. Store the value in a variable first. |
| `Unexpected character ';' in WHILE statement` (or `DO`) | A `;` after an inner `END` or `LOOP` inside a loop. |
| `Unexpected keyword 'X' at the end of IF statement.` | A `;` after an inner `END` inside an `IF` block. |
| `Comment must start on a new line and inline comments are not supported` | A `#` before the `;` of a statement, or after an `IF` or `WHILE` condition. |
| `Comparison with NaN is always false. Use the IsNaN method to check for NaN value.` | `x = NaN` — use `ISNAN(x)`. |
| `Couldn't unescape X` | A single backslash in a string; write `"C:\\data"`. |
| `Too many characters in char literal` | Text in single quotes, such as `'ab'`; text needs double quotes. |
| `Variable name must start with letter`, `Only letters or numbers are allowed in variable name` | A name such as `1x` or `my_value`. |
| `Variable must have initial value provided` | `VAR x;` — give a value, or declare a type: `int x;`. |

## Run-time errors

| Message | Cause and fix |
|---|---|
| `Division by zero` | See [Division by zero](https://taphome.com/en/docs/script/errors/#division-by-zero). |
| `Specified argument was out of the range of valid values.` | `PARSETEXT` found the left pattern but not the right one. Check with `INDEXOF` first. |
| `PARSEJSON - Element not found: 'X'` | The JSONPath matched nothing. Pass `TRUE` as the third argument to get `Null` instead. |
| `Operator 'X' not defined for 'A' and 'B'` | An operation on incompatible types, for example arithmetic with `Null`. Check with `ISNULL` first. |
| `Cannot cast 'A' to 'B'` | A value of a type that cannot be converted, for example text where a number is needed. |
| `Can not directly set value to device variable` | An assignment to a device value outside a Script smart rule. |
| `More than 1 000 000 loops, stopping loop` | A `WHILE` or `DO` loop that does not end. |
| `Cannot use BREAK() outside of WHILE or DO-WHILE` | `BREAK` outside a loop; `CONTINUE` likewise. |
| `Interval 'X' is out of range (0-10000)` | `SLEEP` with a negative interval or longer than 10 000 ms. |
| `Maximum array length is 2048` | `BYTECOLLECTION` from a hexadecimal text of more than 2048 bytes. |
| `Invalid array length. Must be greater than 0 and less than or equal 2048` | `BYTECOLLECTION` with a number of bytes of 0 or more than 2048. |
| `UINT16COLLECTION: count must be between 1 and 2048` | `UINT16COLLECTION`, or `BOOLCOLLECTION` with its own name, with a count outside 1 – 2048. |
| `GETBIT - bit must be between 0 and 15` | A bit or byte outside the type of the value, here a 16-bit value. |
| `GETBIT - value X is out of the 32-bit range (-2147483648 .. 4294967295)` | A decimal value that is not a 32-bit whole number. |
| `Return value 'X' does not match required return type constraint: 'T'` | A device read script returned a type the device value cannot hold. |
| `Response is too long (Nbytes). Maximum supported length is 128KB` | An HTTP response larger than 128 kB. |
| `Invalid register number: X` | A Modbus register outside 0 to 65535. |
| `RegisterValueToWrites: Can't write double.NaN to modbus register` | `NaN` written with `MODBUSW`. |

The messages of the encryption, hash and byte encoding functions, such as `AESDECRYPT - decryption failed, check the key, the iv and the padding` or `FROMHEX - invalid hex digit 'x'`, are listed with each function in [Encryption and hashes](https://taphome.com/en/docs/script/encryption-and-hashes/) and [Byte encodings and checksums](https://taphome.com/en/docs/script/byte-encodings/).

## Context and version errors

| Message | Cause and fix |
|---|---|
| `X function not supported here.` | The function does not work in this kind of script, for example `ADDERROR function not supported here.` in a smart rule. |
| `SLEEP function not allowed in this context.` | `SLEEP` in a Script smart rule or a notification script. |
| `ModbusFunction - unknown modbus device to work with` | A Modbus function outside a Modbus script. |
| `PacketParserFunction - PacketParserContext is null` | A Packet parser function outside a Packet parser script. |
| `DEBOUNCE - invalid argument, must be a device variable` | The first argument of `DEBOUNCE` is an expression, not a device value. |
| `DEBOUNCE - Function is not available` | `DEBOUNCE` in a script without device values that can be debounced. |
| `X function not supported. Please update your core unit to be able to use this feature.` | The Core is older than the function. |
| `Data type 'X' not supported. Please update your core unit to be able to use this feature.` | A type keyword newer than the Core. |
| `Modbus data type 'X' not supported. Please update your core unit to be able to use this feature.` | `Int64`, `UInt64` or `Double` on an older Core; they need TapHome Next 2026.1.40665+. |

Which build each function needs is in [Version requirements](https://taphome.com/en/docs/script/version-requirements/).
