|Topic was automatically imported from the old Question2Answer platform.
I have a tilemap saved as Singleton Called Saplings with 3 tiles in it and i want to print The Cellv of the tile my player is on. but for some reason all it prints out is -1. Please Explain
Some might say its the variable PlayerPosition thats not correct but i use that exact same variable at other points in the same script. only with a different tilemap. The tile map that this script is attached to.
And the Variable is not located in a function only set in the function process wich is the other place i use it. And last but not least the Custom Function is also a process since im calling via a state machine in the process function. wich is really a Physics process
I think thats all the info i need to give
I still think player position is incorrect
You say You use it in other points in script, but perhaps not in the same way :). Did You translate players position with world_to_map() function ??
I get what you’re thinking but heres the catch. I can print out my player position wich i probably should rename to player map position since i do use world to map at both locations where i use them. And it prints out the exact same thing in both places.
Im pretty sure the problem has something to do with it being a called
get_cellv from a singleton. and that somehow causees a problem
Superkrypet | 2021-10-17 16:13
But how can You use TileMap from a singleton and already have its tiles laid in scene on the start of project ? get_cellv only detects tiles of its own tilemap, are You trying to get cellv of the other TileMap ?
i thought it would mirror the settings of the tile map its attatched to in the scene. now i understand that that obviously dosent work. Guess im just dumb. Will it make a difference If I Have the Tilemap saved as a scene and then that scene on autoload. or will i have to do it in some other more advanced way
Edit: i fixed the issue. but only by not having the tilemap as singleton at all.
If you know a way to acces a variable or value from anywhere in the project but not have it be spawned in the scene, i would be happy if you told me. but i guess you can always have just 1 script as singelton with alot of variables acting like a hub for the entire project sending things all over the place. if i know myself right its probably a very messy way to do things but it works for me.
Superkrypet | 2021-10-20 19:47
Yes, this is usually most proficient code structure : to use normal Node as Autoload to hold all variables from entire project. Autoload is especially useful for holding all signals and being main transmitter.
I still can’t imagine what did You needed autoloaded tilemap for, but if You are looking for other ways of exchanging global variables fast, than I would like to point You in direction of Resource class. They are even superior to Autoload in terms of accesibility, but kind of icky to set up. Search YouTube for tutorials about them
Thanks man. Really appreaciate you trying to help me even if the problem was just me being a dumbass and not taking my time to look further into how my project was layered
Superkrypet | 2021-10-21 13:16