Hi all, got a small issue here trying to get information from a dictionary. I'm creating a chunk system for my game and storing the node of a chunk and a basic coordinate system into a dictionary. The start area is chunk 0,0 and the next chunk to the right is 1,0.
this is the simple code written on the Chunk script:
Core.all_chunks[Vector2(x,z)] = self
I have a Core script that runs stuff for the game, and includes the dictionary. So far this works just fine, if I run a Print by passing in a Vector2 I get the appropriate Chunk node.
But for some reason, when I try to get the Chunk in other areas, its not working, and I don't know why.
I've got this function on the Player to check which Chunk they are in after moving:
`func get_current_chunk() -> Vector2:
var xPos
var zPos
if position.x >= 0:
xPos = floor(position.x / 64)
else:
xPos = ceil(position.x / 64)
if position.z >= 0:
zPos = floor(position.z / 64)
else:
zPos = ceil(position.z / 64)
return Vector2(xPos, zPos)`
The Chunk size is 64 tiles, so I'm just taking the player location and dividing by 64 then rounding to see where the player is. This seems to be working just fine so far. But when I pass this information to the code above to get which Chunk the player is in, I get an error and I'm not sure why.
If I try to set the Current_Chunk variable on the Player to the current Chunk that they are on:
Current_Chunk = Core.all_chunks[get_current_chunk()]
I get errors. It says I have an invalid get index '(0,0)' which doesn't make a ton of sense. All the chunks are added to the dictionary long before the player is instantiated and needs to know which chunk its on. Why would I be getting this error? I can even check the dictionary to make sure the Chunk is there, and it is there.