Invalid access to property or key '22' on a base object of type 'Dictionary'.

just started using godot a couple of days ago. trying to make a name generator which will string together random consonants and vowells. getting this error ‘Invalid access to property or key ‘22’ on a base object of type ‘Dictionary’.’

extends Node2D

var villager_scene = preload("res://Scenes/villager.tscn")

func _input(event):
	if event.is_action_pressed("select"):#set up an input in project window. event input is picked up, if the input matches, things happen.
		var vowells = {"a":0, "e":1, "i":2, "o":3, "u":4}
		var consonants_rare = {"w":5, "x":6, "z":7, "k":8, "q":9, "j":10}
		var consonants_common = {"l":11,"m":12, "n":13, "b":14, "c":15, "r":16, "s":17, "t":18, "v":19, "d":20, "f":21, "y":22, "g":23, "p":24, "h":25}
		var names: Array[String]
		var name_length = randi_range(3, 8)
		for i in name_length:
			var type = randi_range(0, 25)
			if type < 6:
				var let = (vowells[type])
				names.append(let)
			elif type > 5 and type <= 11:
				var let = (consonants_rare[type])
				names.append(let)
			else:
				var let = (consonants_common[type])
				names.append(let)
		print(names)

You have mixed up the keys and values. You want it the other way around:

var vowells = {0: "a", 1: "e", 2: "i", 3: "o", 4: "u"}
var consonants_rare = {5: "w", 6: "x", 7: "z", 8: "k", 9: "q", 10: "j"}
...
2 Likes