This is an automated archive made by the Lemmit Bot.

The original was posted on /r/godot by /u/Balarius on 2024-10-13 16:40:16+00:00.


The code below used to take up just…all the space, an if statement for every word amongst other inefficient code. Im sure theres an even better way of doing the same thing but man, Woo! Just felt like sharing my days minor accomplishment with y’all.

Learning Note!: I learned doing this, that - Array.pop_front( ) is immeasurably less efficient than Array.pop_back( ). Because pop_back only returns (selects) and removes the final entry in the array, so its only targeting one entry. pop_front returns and removes the first entry but then has to shift all other entries down 1 spot because there always has to be a 0 option in an array.

func chooseWord():
  if WordArray.is_empty():
    print("Resetting WordArray")
    WordArray = ["Rat", "Car", "Box", "Map", "Key", "Pig", "Can", "Dog", "Hat", "Bat", "Bee",             "Arm", "Fly", "Saw", "Cow", "Ear", "Ice", "Sun", "Eye", "Gem", "Owl"]

    WordArray.shuffle()

  word = WordArray.pop_back()
  $ImageHint.texture = load("res://images/" + word + ".png")