- Edited
Hello everyone,
I am new to GODOT and trying to create a 2d tower defense game in Godot4 by watching some YouTube vdos.
This is my code:
extends Node2D
#create global variables
var map_node
var build_mode = false
var build_valid = false
var build_location
var build_type
#create functions
func _ready():
map_node = get_node("Map1") ## Turn this into variable based on selected map
for i in get_tree().get_nodes_in_group("build_buttons"):
var button_name = i.get_name()
i.connect("pressed", Callable(self, "initiate_build_mode").bind(button_name))
func _process(delta):
if build_mode:
update_tower_preview()
func _unhandled_input(event):
pass
func initiate_build_mode(tower_type: String) -> void:
build_type = tower_type + "T1"
build_mode = true
get_node("UI").set_tower_preview(build_type, get_global_mouse_position())
func update_tower_preview():
var mouse_position = get_global_mouse_position()
var current_tile = map_node.get_node("TowerExclusion").local_to_map(mouse_position)
var tile_position = map_node.get_node("TowerExclusion").map_to_local(current_tile)
#check valid build location
if map_node.get_node("TowerExclusion").get_cellv(current_tile) == -1:
get_node("UI").update_tower_preview(tile_position, "ad54ff3c")
build_valid = true
build_location = tile_position
else:
get_node("UI").update_tower_preview(tile_position, "adff4545")
build_valid = false
func cancel_build_mode():
pass
func verify_and_build():
pass
When I run the code, menu page is fine. I can click start game. But when I click at the turret button, the game stop and show error like this :
Invalid call. nonexistent function 'get_cellv' in base 'TileMap'
Can anyone tell me what should I use instead of 'get_cellv'? Thank you.