#Requested Assistance with Custom Tile Data Detection (Top Down 2D Project)

49 messages · Page 1 of 1 (latest)

faint solstice
#

Probably my biggest roadblock so far. I've tried looking into it for the last two days with no success. every method that I've seen online I end up not understanding enough to be able to implement it into my own project. I will be detailing my current project setup so it'll hopefully be easier to tell where I am going wrong

#

Requested Assistance with Custom Tile Data Detection (Top Down 2D Project)

#

this is how I am handling my movement

#

and I have this custom data property for each tile

tardy fox
#

so do you need the custom data of the tile the player is on?

faint solstice
faint solstice
#

just like being able to read the number in the code or something if that makes any sense

tardy fox
#

do you have a reference to the tile map in the player script?

faint solstice
#

hm not yet i havent looked into that yet, how would you refrence to something thats not a child?

tardy fox
#

the best way is to have an autoload that gets the references and then the scripts and access that. do you know how to make an autoload?

#

if you don't. Project > Project Settings > Autoload

#

so your tile map, or maybe the world node, would have a script on it that gives the autoload the reference to itself like:

func _ready():
  references_autoload.tile_map = self
```then the player would get that reference like:
```swift
func _ready():
  set_deferred("tile_map", references_autoload.tile_map)
faint solstice
#

oh ok got it (sorry for the delay i was looking into what exactly an autoload did and it makes sense to me now)

#

ok so now i have my refrence

tardy fox
#

now you need the map coords of the tile. TileMap has a local_to_map method so you just need to get the player's position local to the tile map. like this:

#this in on this player
func _process(delta):
  var player_tile = tile_map.local_to_map(tile_map.to_local(position))
#

then you can get the cell's tile data with tile_map.get_cell_tile_data(0, player_tile)
(I'm assuming the ground tiles are on layer 0)

#

then call get_custom_data on the result of the get_cell_tile_data with the name of the custom data layer you want

#

it will return the value

faint solstice
#

alr alr, ill try this

faint solstice
#

so i keep getting this error, tried to debug it myself but failed

faint solstice
tardy fox
tardy fox
faint solstice
tardy fox
#

the underscore is just for casing style to make it easier to read. you may just have a typo

faint solstice
#

hmm, so ive tried a few things at this point, autoloading it from a script attatched to the tileset, copy and pasting every name in every intance its refrenced. yet still nada

tardy fox
faint solstice
#

this is all that i have on it

tardy fox
#

well it looks like you're trying to get tile_map from world.gd instead of from tilemap_autoload

faint solstice
#

hm so i do have to set the refrence to the autoload in a script attatched to the Tilemap and use self?

tardy fox
#

what you have there is fine. the error will be coming from somewhere else. what does it look like in the player script?

#

and for good measure, the autoload aswell

faint solstice
tardy fox
#

the actual code of the autoload. it's just a script

faint solstice
#

oh well i put the autoload code in the world script i might have done this wrong then hang on

tardy fox
#

it just needs a variable to hold the tile map as it's being transferred

faint solstice
#

ohhhh ok yeah now I get it, now I don't get that error I'll try to implement the rest of the system

fingers crossed I get the rest first try 💀

#

ok ok hopefully this is the final error but theres something up with the "to local" method

tardy fox
#

try replacing the tile_maps with tilemap_autoload.tile_map

#

that's saying the reference to tile_map is null. it's nota problem with to_local necessarily

faint solstice
#

OOOOH
Yes this is doing something

#

thank you so much

#

ill mess around a bit after a break from this and if it works without issue than ill close

tardy fox
#

good luck!

faint solstice
#

again, thank you