Finding a better way to get which position in the array I'm at

Godot Version

4.6.2

Question

	hallucinationTimer += delta
	for i in currentHallucinations:
		var T = 0
		for ii in i.boltArray:
			if ii != 0:
				if fmod(hallucinationTimer, 1.0 / ii) >= 1.0 / ii - delta:
					spawnBolt(10 ** T, i.position)
			T += 1

The above code block is my code for not only a custom timer, but also triggering a function to spawn an instance of a “bolt” whenever the timer hits certain values that correspond to an array telling this code how many times per second it should spawn a bolt.

The code works; there’s technically no problems with it, but the variable T is ugly implementation, and I can’t use find because of the fact that values can be the same (for example, three 1’s in a row) and it’ll just grab the furthest down value.

Does anyone have a better way of going about this? Or is this actually good implementation?

I’m not sure what you want to achive but when you need to identify a value through a key better use a Dictionary.

You can iterate but you can access a particular value using its key too.

This is like a spawn sequencer? Use a tween.

I think instead of relying on loop computation everytime, you can use pointer_variable (just a jargan). Simply need a variable that holds the information like index number of array. If you need to hold one value at a time in the array this works fine but if you want to expand you simple increase number of variable that holds the current position and after everytime your array updates or your function updates just update that pointer variables. I hope this is helpful.