Godot Version
Godot 4.1
Question
How can i randomly add an instance around the map on a specific tile from a tilemap? I have tried multiple things but i still cant understand anything and i cant get anything to work. I use procedural generation to generate my dungeon and i want to place things on the floor on random spots around the map only on the floor tile(i use the walker generator to generate the map from the gaea addon). I have been trying to do it for so many days, i have seen a lot of reddit and godot posts about this but i do not understand anything . Can someone please tell me how to do it?
update i tried something
this is what it looks like but for some reason it shows an error. Its supposed to check for specific tiles and on top of them instantiate a scene. A friend suggested that it might be because the scene loads too fast, i tried await get_tree().create_timer(10).timeout do the thinng and await get_tree().process_frame but it didnt work, it still shows the same error. Can anyone help?
This error states that ore.gd
does not have a variable named coordinates
, or that it isn’t of type Vector2i
my man you are the best of the best from the best world thats in the best dude universe, you are an angel that fell from heaven i can not express my gratitude with any words. I just added a variable named coordinates in the ores script, added the functions await get_tree().process_frame and it works. Thank you so much. Although i do have a question. How do you understand the errors? like is there a guide somewhere or smth?
There might be a guide, though if they could make the error messages clearer I’m sure they would.
I look at what it’s pointing out: ‘coordinates’, ‘Node2D (ore.gd)’, and ‘Vector2i’. Since it’s an invalid index that means one of these three is missing, scripts such as ‘ore.gd’ are unlikely to be referenced in your code. I can see instance
being indexed with coordinates
in the script and line it is pointing to, so I figure that’s the “invalid index” and your script ‘ore.gd’ is missing that variable.
I question though, why did you add coordinates
to the script? Do you intend to use coordinates
? You could’ve deleted the line if not.
if you are talking about why i added the var coordinates in the map script its needed cause otherwise it just spawns too many scenes and its laggy. But if you are talking about why i added it in the ore scene script idk you said the error says its missing that var so i added that var and then everything went workity work. Also thanks for the explanation
Right but that erroneous line doesn’t need to exist by virtue of being there, why was instance.coordiantes = coordinates
put there in the first place? If creating the coordinates
variabe on ‘ore.gd’ doesn’t have a good reason to exist then this line doens’t have reason to exist either, and was merely causing you errors.