if grid_board and grid_board.get_cell_tile_data(0,tile_pos) and grid_board.get_cell_tile_data(0,tile_pos).get_custom_data("obstacle"):
return true
else:
return false
to something like
if grid_board.get_cell_tile_data(0,tile_pos).get_custom_data("obstacle"):
...
Each part might or might not exist/return a value so I have to check if each parts exists first.
If there isnt a short hand, why not? (is it harder than i’m imagining it? parse token → try catch)
There’s a number of ways you could deal with this. But what exactly is the problem you’re trying to fix? Why do you have to check if each part exists?
Sadly there’s no try/catch in Godot. If something throw an error, you can get the value in a variable and evaluate it usually. So you might be able to do something like:
var result = grid_board.get_cell_tile_data(0,tile_pos).get_custom_data("obstacle")
if result == true:
.
.
.
It’s hard to know what problems you’re trying to solve with just that line of code. Why would the grid_board ever get to this line of code without existing? Why would a grid_board exist without any data and get to this line of code?
It boils down to the fact that each function could do anything and return anything, so it can’t particularly be a language feature without an optional type built in, this is a popular issue, nullable types, but it is hard to implement, especially retroactively. Even with optional types I’m not sure it would be much shorter.