CombinationGenerator in 3.1

Just a small tipp for those who are using 3.1 to follow this course.
GDScript has a keyword named class_name which allows to register a global class name for a script.
I used this for the CombinationGenerator like this:

class_name CombinationGenerator extends Node

static func generate_combination(length):
	var combination = []
	for number in range(length):
		randomize()
		combination.append(randi() % 10)
	return combination

which then allows me to just do

func generate_combination():
	combination = CombinationGenerator.generate_combination(combination_length)

in Computer.gd, as it is globally accessible thanks to class_name. :slight_smile:

Privacy & Terms