0 votes

I'm new with godot. im trying to generate a world with perlin noise but i cant set the tiles of the tilemap because is like my tilemap is pointing to null or something

const ANCHO = 100
const ALTO = 100
var open_simplex_noise
const TILES = {"pasto":5 , "agua":0 , "tierra":6}
onready var grilla = $TileMap

func _ready():
    randomize()
    open_simplex_noise = OpenSimplexNoise.new()
    open_simplex_noise.seed = randi()
    open_simplex_noise.octaves = 4
    open_simplex_noise.period = 256
    open_simplex_noise.persistence = 0.349
    _generate_world()

func _generate_world():
    var tipo_celda
    for x in ANCHO:
        for y in ALTO:
            tipo_celda = _generate_cell_type(open_simplex_noise.get_noise_2d(float(x),float(y)))
            grilla.set_cell(x,y,tipo_celda)
func _generate_cell_type(noise_num):
    if noise_num < 0.5:
        return TILES.pasto
    elif noise_num < 0.6 && noise_num > 0.5:
        return TILES.tierra
    else:
        return TILES.agua

the var grilla keeps null and thats generating the error but i dont know why it keeps null after the assignment

in Engine by (14 points)

Hi,
print(grilla)
See that it's set to a Tilemap.
If it's not... maybe use find_node to get the node.

it pointed null with find_node worked fined. thanks

1 Answer

+1 vote

it pointed null with find_node worked fined. thanks

Note that find_node looks through all child-nodes, so (depending on your tree and how often you call the method) it can be a lot more inefficient than using get_node! If get_node returned null, that simply means you used the wrong path. You can use the following code snippet to get the correct path:

var node = find_node("<NodeName>")
print(node.get_path())           # prints the absolute path
print(self.get_path_to(node))    # prints the relative path
by (10,582 points)
Welcome to Godot Engine Q&A, where you can ask questions and receive answers from other members of the community.

Please make sure to read Frequently asked questions and How to use this Q&A? before posting your first questions.
Social login is currently unavailable. If you've previously logged in with a Facebook or GitHub account, use the I forgot my password link in the login box to set a password for your account. If you still can't access your account, send an email to [email protected]otengine.org with your username.