Cannot convert argument from object to vector 2i

spawn a block at a location not triggered by the mouse not painting a map spawning blocks with walls on them when there is no floor layer in an isometric seen. standing on a block should tell the console to print ‘floor’ or whatever. the raycast is colliding with floor layer if not call the rng tile and place there.

the issue is the raycast cant place set cell when that code is ran by raycast it says vector 2i cant be an int the tile node says it cant be used to detect

id like it to be able to spawn before the player gets there but with some experimenting the raycast when hitting from the inside always detects from players location so i moved 4 raycasts equal distance away like a dpad to detect non contact thats more or less why raycast but can be in 2dcollision too

So which location if not the mouse?

Again what you don’t want, but I need to know what you do want.

So what ever is standing would call

# something that stands.gd
@export var floor_layer: TileMapLayer

func what_am_i_standing_on() -> void:
    var tile_data = floor_layer.get_cell_atlas_coords(floor_layer.local_to_map(self.position))
    if tile_data == Vector2i(-1, -1):
        print("Nothing!")
    else:
        print("floor! ", tile_data)

So let’s build on that last snippet.

# something that stands.gd
@export var floor_layer: TileMapLayer

func standing_on_floor() -> bool:
    var local_position := floor_layer.local_to_map(self.position)
    var tile_data := floor_layer.get_cell_atlas_coords(local_position)
    return tile_data != Vector2i(-1, -1)

func _process(_delta: float) -> void:
    var random = randi_range(0,6)
    var local_position := floor_layer.local_to_map(self.position)
    if not standing_on_floor():
        var _land = Vector2i(random, 0)
        floor_layer.set_cell(local_position, 0, _land)

are atlas coords the x and y of the map?

1 Like

No they represent coordinates for a tile in the TileSet, return -1, -1 if a tile isn’t found

ah youre awesome thank you

its saying cannot call method local_to_map on a null value im trying to figure that out now

An @export variable must be assigned, check the inspector for that node.

@export var floor_layer: TileMapLayer i have youre saying i need @export on local position even if its in the character2d im calling maplayer from another node tried it in the ratcast but got the same message but it seems with the way its going this fits best in the character

No, the script is set up fine, only floor_layer needed @export. You need to go into your world scene, select the character and Assign “Floor Layer” your floor TileMapLayer node.

how do i do that am i renaming it? or drawing with node

2024-09-05-155839_563x463_scrot

@export variables show up in the properties inspector. This one can be assigned to any TileMapLayer node you want to query.

i dont have build-in script on 4.3 in the inspector

Do you have your scripted node selected? It probably won’t say “Built-in script”, instead what ever you named the script attached to said node.

Screenshot (1335)

okay i guess it is already

It would be near the top, unless you have script syntax/compilation errors (red lines immediately visible within the editor).

so thats not the i need to assign in the inspector

no its assigned

oh i cant