Search code examples
pythonpycharmpython-3.8roguelikelibtcod

Roguelike Development Roadblock! libtcod.map_compute_fov depreciated?


I'll try to be both brief and thorough.

I am following the tcod Rouguelike tutorial at the following link:

http://rogueliketutorials.com/tutorials/tcod/

I am using PyCharm Community Edition, though I don't think that much matters. All was going well until the end of Part 4, where we implemented an FOV for the player. When I try to run the main engine using the following code (given in tutorial):

def recompute_fov(fov_map, x, y, radius=1, light_walls=True, algorithm=0):
libtcod.map_compute_fov(fov_map, x, y, radius, light_walls, algorithm)

The compiler spits out the following error:

File "C:\Users\drago\anaconda3\envs\Roguelike\lib\site-packages\tcod\libtcodpy.py", line 3320, in map_compute_fov
    m.compute_fov(x, y, radius, light_walls, algo)
AttributeError: 'NoneType' object has no attribute 'compute_fov'

Process finished with exit code 1

I at least know enough to know it's talking about the tcod package itself. But I didn't understand. Thankfully, PyCharm gave me a little insight...

PyCharm's insight on libtcod.map_compute_fov

So I followed its advice and changed libtcod.map_compute_fov to libtcod.map.compute_fov

It gave me another error:

File "C:\Users\drago\PycharmProjects\Roguelike\map_objects\fov_functions.py", line 13, in recompute_fov
    libtcod.map.compute_fov(fov_map, x, y, radius, light_walls, algorithm)
TypeError: compute_fov() takes from 2 to 5 positional arguments but 6 were given

Process finished with exit code 1

So, once again, PyCharm was able to tell me about this new function, and how it used different values. Instead of an FOV_map, it uses something called pov, and that pov requires an array of 2 values. It also has something to do with transparency, which at this point is going over my head for the purpose of what I want to accomplish.


I'm still learning Python, thus the tutorial. I get what an array is. But I have no idea how to make my existing code work with this new function/module (I get the two mixed up), since the old one was depreciated.

Any help would be appreciated.

I am using Python 3.8 as well.


Solution

  • I was just having this same problem and found that putting

    def recompute_fov(fov_map, x, y, radius, light_walls=True, algorithm=0):
        libtcod.map_compute_fov(fov_map, x, y, radius, light_walls, algorithm)
    

    at end of the code in fov_functions.py fixed the

    "AttributeError: 'NoneType' object has no attribute 'compute_fov'"

    problem i was having like you.

    here is how the tutorial author (as of part 4) had fov_functions.py set up:

    import libtcodpy as libtcod
    
    
    def initialize_fov(game_map):
        fov_map = libtcod.map_new(game_map.width, game_map.height)
    
        for y in range(game_map.height):
            for x in range(game_map.width):
                libtcod.map_set_properties(fov_map, x, y, not game_map.tiles[x][y].block_sight,
                                           not game_map.tiles[x][y].blocked)
    
        return fov_map
    
    
    def recompute_fov(fov_map, x, y, radius, light_walls=True, algorithm=0):
        libtcod.map_compute_fov(fov_map, x, y, radius, light_walls, algorithm)
    

    here is the link to the code as of part 4 that the author puts at the end of each part of the tutorial: https://github.com/TStand90/roguelike_tutorial_revised/tree/part4 this is where i found the fov_functions file that i compared to mine

    Where the author puts the code at the end of each part: https://i.sstatic.net/AgjCp.png

    Hopefully this helps you out!