this post was submitted on 13 Oct 2024
1 points (100.0% liked)

Godot: The open source game engine

21 readers
1 users here now

A community for discussion and support in development with the Godot game engine.

founded 1 year ago
MODERATORS
 
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")

no comments (yet)
sorted by: hot top controversial new old
there doesn't seem to be anything here