Pulse Works Studio

Parse Error: Cannot assign a value of type String to variable "hp" with specified type int.

A typed variable cannot hold a value of another built-in type.

Cause

Once hp is declared as int, a String initializer or assignment is rejected at parse time. This often comes from reading JSON or a line edit, both of which give you text. Convert the text before the assignment.

Fix

var hp: int = 10

func apply_line(text: String) -> void:
	if text.is_valid_int():
		hp = text.to_int()

Related

Godot Dev Tools is a Pulse Works Studio project. All error explainers.