Skip to reading
GDScript Programming & Godot

Distance()

Edition 0.86.4.1 HF1

0.86.4.1 Hotfix 1 edition. Earlier lessons and screenshots retain their original version context; revised references and supplements describe the newer behavior.

Download PDFView PDF page
On this page
Code example
Distance(first: Variant, second: Variant) -> float

Measure matching Vector2/Vector3 or integer-vector values, or a numeric absolute difference.

Returns: Float; 0 for unsupported pairs.

Code example
Distance(Vector3.ZERO, Vector3(3, 0, 4))

It does not automatically look up record/node positions from a proxy.

Format()#

Code example
Format(template: Variant, values: Variant = {}) -> String

Replace dictionary {key}, array {0}, or scalar {0}/{value} placeholders.

Returns: String.

Code example
Format("Score: {value}", 25)

No embedded expression evaluation or translation registration is implied.

ToJSON()#

Code example
ToJSON(value: Variant, indent: String = "") -> String

Serialize ordinary data to JSON text.

Returns: String.

Code example
ToJSON({"open": true, "score": 5}, "  ")

FromJSON()#

Code example
FromJSON(text_value: Variant, fallback: Variant = null) -> Variant

Parse JSON text with an explicit parser and fallback on failure.

Returns: Parsed value or fallback.

Code example
FromJSON('{"open":true}', {})

Valid JSON null remains null. Native vectors, resources and nodes need an explicit representation for portable JSON.

Page 86 of 378Permalink
Go to page