Making a random item generator but want a minimum of 5 of one value represented. This array has 5 'X' (meaning item) and 25 'O' (meaning empty) with them randomly dispersed amongst the 30 "chests" with each one removed as found in a loop. Trouble is that it only returns half the array before returning. I am using a variable to check the max size of the array with a minus for bug-stopping state. What am I missing?
extends Node
class_name itemLoader
var itemBank = [ 'X','X','X','X','X',
'O','O','O','O','O',
'O','O','O','O','O',
'O','O','O','O','O',
'O','O','O','O','O',
'O','O','O','O','O']
var itemPull = itemBank.duplicate()
var rng = RandomNumberGenerator.new()
func _ready():
rng.randomize()
func chestopen():
for i in itemPull:
var t = int(itemPull.size())-1
var r = rng.randi_range(0,t)
var buffer = Timer.new()
add_child(buffer)
buffer.set_wait_time(0.5)
if str(itemPull[r]) == 'O':
print('Chest empty!')
itemPull.remove(r)
t = int(itemPull.size())-1
buffer.start()
yield(buffer,"timeout")
if str(itemPull[r]) == 'X':
print('Key found!')
itemPull.remove(r)
t = int(itemPull.size())-1
buffer.start()
yield(buffer,"timeout")
print("\n")
print("list empty.")
func restock():
itemPull = itemBank.duplicate()
print("\n")
print("Restocked!")
print("\n")
I am using a timer because i thought a buffer might slow it down enough for me to see something. It did not but it adds minor sequencing for debugging sake.