Using shuffle() Method on Arrays Always Returns Null

:information_source: Attention Topic was automatically imported from the old Question2Answer platform.
:bust_in_silhouette: Asked By scrubswithnosleeves

Hey All,

Trying to use the shuffle() method on an array returns null for me. Here is a simple example:

func _ready():
	var nums = [1,2,3,4,5]
	print(nums)
	print(nums.shuffle())

Output:

[1, 2, 3, 4, 5]
Null

What am I doing wrong? It doesn’t help if I capture it with something like:

numsShuffled = nums.shuffle()

It also doesn’t help if I move it out of the _ready() function

Am I missing something or do I need to write my own shuffle function?

:bust_in_silhouette: Reply From: KurtBlissZ

Shuffle returns void.

func _ready():
	var nums = [1,2,3,4,5]
	print(nums)
	print(nums.shuffle())
	print(nums)
	
:bust_in_silhouette: Reply From: Ertain

The shuffle() function doesn’t return anything; it shuffles the array on which it was called.