how to simplify my code?
Asked Answered
P

1

0

Greeneyed

for node in hand_block.get_children():
	node.visible = false
hand_block.get_node(slot_item.item_name).visible = true
Portuguese answered 9/12, 2023 at 13:51 Comment(0)
W
0

maybe you can use add_to_group.

Set when initializing nodes

grass_node:
node.add_to_group("block_grass")
node.add_to_group("all_block")

stone_node:
node.add_to_group("block_stone")
node.add_to_group("all_block")

calling method

get_tree().call_group("all_block","set_visible",false)
get_tree().call_group(slot_item.item_name,"set_visible",true)

or

for node in hand_block.get_children():
    if node.is_in_group("all_block"):
        if node.is_in_group(slot_item.item_name):
            node.visible = true
        else:
	    node.visible = false
Wantage answered 9/12, 2023 at 15:25 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.