How to get .x and .y int values from array containing Vector2

Godot Version

4.2.2 (Steam)

Question

I have a rough draft for a script I want to use to generate paths for a procedurally generated dungeons. I have already (mostly) finished room generation, where 9 randomly sized rooms will appear in a 100 cell radius. It is 3D. The coordinates to every door of every room are stored as Vector3 in an array named “door_array”. I want to use these coordinates with AStarGrid3D to generate a path between rooms, but anytime I start the scene, it instantly crashes and a debug error shows:

Invalid get index ‘(71, 69)’ (on base: ‘Array[Vector2i]’).

The 71 and 69 are just whatever the first two coordinates of the seed are (I think). Here is the function:

	while doors_pathed < total_rooms:
		if total_rooms - doors_pathed == 1 and total_rooms & 1:
			doors_pathed += 1
		else:
			doors_pathed += 2
			path = astar_grid.get_id_path(Vector2i(door_array[doors_pathed-1].x,door_array[doors_pathed-1].z),Vector2i(door_array[doors_pathed].x,door_array[doors_pathed].z))
			for cell in path:
				grid_map.set_cell_item(Vector3(cell.x,0,cell.y),1,1)```
for cell in path:
    grid_map.set_cell_item(Vector3(path[cell],0,path[cell]),1,1)

this line is probably wrong, though maybe not the error you are getting. The for loop already indexes into path so path[cell] will likely be out of bounds. you want to just use cell as I understand it. Reading into A* this cell value is an ID so I am not sure where you are to plug it into.

Could you paste your script again with code formatting, use the </> button to create three ticks like so

```
type or paste code here
```

Which line gives the error, and what is the error exactly?

1 Like

Nice, it worked. Thanks!

In retrospect I probably could have figured that out by myself but I’m too lazy so thanks :slight_smile:

Whoops, sorry didn’t read this until after I tried your solution and replied. I do not use these forums often, I will make sure to format my code. It gives me the error on the line with the astar.get_id_path()

that function call is also invalid, get_id_path takes two integer arguments, not two Vector2i arguments. An error, but still I doubt this is your current error, try print(doors_pathed) before it is called, maybe it’s just out of the range of door_array values.

Really? It works for me. How would it use integers anyway, if what the purpose of it is to create a path between 2 points?