Material Box

Material Box

WEB Design & Material Images

Godot - Getting the Sum of an Array

Godot

This code example shows how to get the sum of an array in GDScript.


Use `reduce()` to get the sum of an array.
It calls the specified Callable for each element in the array and accumulates the result.

var array = [5, 6, 7]

var sum = array.reduce(func(acc, num): return acc + num)

print(sum)
# 18

Godot

TitleGodot - Getting the Sum of an Array

CategoryGodot

Created

Update

AuthorYousuke.U