Skip to content

Invalid operands 'Nil' and 'int' in operator '+' in Godot 4

By Eduardo Orellana · Updated

One side of the operator is null: a variable that was declared without a value, or a lookup that found nothing. hp + 10 with hp still null stops with Invalid operands 'Nil' and 'int' in operator '+'. Give the variable a value when you declare it, var hp := 100, or check it is not null before the arithmetic.

AppImage, x86_64. Ubuntu 22.04, Debian 12, Fedora 39 or newer.

Intel or AMD Chromebook, with Linux turned on.

Download for macOSDownload for WindowsDownload for Linux

What Godot is checking

Nil is the type of null in Godot. An untyped var declared with no value holds null, and no arithmetic operator is defined between Nil and a number, so the evaluator stops with the two type names.

A typed declaration avoids it: var hp: int starts at 0, not null, and var hp := 100 starts at 100.

More on this: Cannot get return value of call to "…()" because it returns "void" in Godot 4

Reproduce it

A health variable declared without a value, then used in a sum.

GDScript
extends Node

var hp

func _ready() -> void:
	print(hp + 10)
	print("after")

What Godot 4.7.2 prints

Output
Godot Engine v4.7.2.stable.mono.official.ed1daf0bf - https://godotengine.org

SCRIPT ERROR: Invalid operands 'Nil' and 'int' in operator '+'.
   at: _ready (res://answers/invalid-operands-nil-and-int/repro.gd:6)
   GDScript backtrace (most recent call first):
       [0] _ready (res://answers/invalid-operands-nil-and-int/repro.gd:6)

Fix it

Declare it with a type and a starting value.

GDScript
extends Node

var hp := 100

func _ready() -> void:
	print(hp + 10)

What the fixed script prints

Output
Godot Engine v4.7.2.stable.mono.official.ed1daf0bf - https://godotengine.org

110

Run this fix with your agent

Flockbay is the Godot editor with an AI agent built in. Paste this into Flockbay's chat, or into Claude Code or Codex connected to Flockbay over MCP: the agent finds the cause in your project, applies the fix, runs the game headless and reads Godot's output to check it.

More on this: Cannot infer the type of "…" variable because the value is "null" in Godot 4

Prompt
My Godot 4 project prints this error: "Invalid operands 'Nil' and 'int' in operator '+'.". Find where it comes from and fix it. One side of the operator is null: a variable that was declared without a value, or a lookup that found nothing. hp + 10 with hp still null stops with Invalid operands 'Nil' and 'int' in operator '+'. Give the variable a value when you declare it, var hp := 100, or check it is not null before the arithmetic. Then run the game headless and check that Godot's output no longer shows it.

A lookup that returned null

Dictionary.get(key) returns null for a missing key, and a function with no return statement on some path returns null. The arithmetic after it fails with 'Nil' on one side. Pass a default, stats.get("hp", 0), or return a value on every path.

More on this: Expected end of statement after variable declaration, found "Identifier" instead in Godot 4

GDScript
var hp = stats.get("hp", 0)
print(hp + 10)

Verified on Godot 4.7.2

Both scripts on this page were run headless on Godot 4.7.2 (4.7.2.stable.mono.official.ed1daf0bf) on 18 October 2026, and the output above is what Godot printed, unedited.

Where the check lives in Godot's source: gdscript_vm.cpp line 795, the message.

Questions

What is Nil in Godot?
The type of null. An untyped variable with no value, a missing dictionary key read with get(), and a function that returns nothing all give Nil.
Why did the editor not warn me?
The variable is untyped, so the analyzer cannot know it is null when the line runs. Typing it, var hp: int, gives it 0 instead of null.

Flockbay's agent reads Godot's debugger output and fixes errors like this one in your project, on the official Godot.

Download Flockbay free