S

Non-static function "is_cell_occupied" can only be called from an instance

Spudward
posted to: The EntityPlacer

Hello, while following the lesson I am getting the above error.  I was following the lesson and have even copy/pasted the code at this point and still am getting this error.  Simulation and EntityTracker code I have also now copy/pasted so I am not sure what is going on. 


  • Nathan Lovato replied

    this suggests that the _tracker variable hasn't been initialized. The thing is you should get a null error, but you assigned the EntityTracker class to the _track variable. While in the series we don't assign the class, we just set the type hint. Notice how, unlike in your code, we don't use the equal sign.

    var _tracker: EntityTracker

    Then, this EntityTracker variable needs a reference to an instance of the EntityTracker class. We provide it from the Simulation.gd script:

    var _tracker := EntityTracker.new()
    #...

    func _ready() -> void:
    _entity_placer.setup(_tracker, _ground, _player)
    #...

    We have to call this setup() function to provide the entity tracker to our node, otherwise, we can't keep track of entities on the game board.

    I hope this helps.