Skip to reading
GDScript Programming & Godot

7. Operators and arithmetic

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
Code example
func run() -> Array:
    var points: int = 10
    points += 5
    points *= 2
    var average: float = float(points) / 4.0
    var remainder: int = 11 % 3
    return [points, average, remainder, 2 ** 3]
Source table from 7. Operators and arithmetic, page 15
Operator familyMeaning
+ - * / % **Arithmetic, integer remainder, exponentiation
= += -= *= /=Assignment and update
== != < <= > >=Comparison
and or notBoolean logic; and/or short-circuit
in, not inMembership
is, asType test and object cast
& | ^ ~ << >>Integer bit operations; useful for flags and masks

Dividing two integers performs integer division. Use a float operand or explicit conversion when you need a fractional result. = assigns; == compares. GDScript has no ++ or --: use += 1 or -= 1.

Parentheses make mixed expressions clear. For a condition involving both and and or, group the part you intend to combine first. Do not use bit operators as substitutes for ordinary Boolean tests.

Page 15 of 378Permalink
Go to page