Talk:Complete Roguelike Tutorial, using python+libtcod, part 1

From RogueBasin
Revision as of 07:12, 17 January 2019 by Brodavi (talk | contribs) (→‎error with libtcod 1.6.2 configure: new section)
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to navigation Jump to search

Instead of the awkward

    if not first_time:

may I suggest to just put things in the order in which they are meant to be executed?

    libtcod.console_set_foreground_color(0, libtcod.white)
    libtcod.console_print_left(0, playerx, playery, libtcod.BKGND_NONE, '@')
    libtcod.console_print_left(0, playerx, playery, libtcod.BKGND_NONE, ' ')

    exit = handle_keys()
    if exit:

-- relet 16:48, 18 October 2010 (UTC)

Sure. The logic you're pointing out was only added as an afterthought to correct a small bug: the first frame for a turn-based game wouldn't be shown while waiting for input. When someone pointed out the bug this was added as a quick-fix. I'll change it to the better solution soon (remember I also have to make the same change to all the "whole code" pages...). Jotaf 16:24, 23 October 2010 (UTC)
Done. Had to manually update about 10 "whole code" pages but it's for the better, I never liked that logic anyway. Jotaf 22:35, 7 November 2010 (UTC)

I'm very much enjoying this tutorial! It is immensely helpful and informative. However, I have two questions, that I, as a python-noob, don't understand:

  1. libtcod.console_flush() comes before the code that overwrites the '@' with ' '. Doesn't that mean, that the old character gets overwritten AFTER the output? I don't understand how that works.
  2. When I press left arrow, and then up right after, my @ moves left two times and up once. Is that because of console_is_key_pressed? Is that the way it's supposed to work?

Thank you! SkaryMonk 13:17, 11 May 2012 (CEST)


N00b here. I'm having a difficult time translating this tutorial for OS X 10.6.8. I've downloaded an OS X version of the libtcod library, but I'm not sure which files to put in the working directory. I'm not sure if I have to install libtcod onto my system in some more general way, and if so, how I would do that.

Could anyone give a quick rundown of that process?

UPDATE: I managed to install libtcod through homebrew (which seemed the easiest possible way to do it). I used it to compile and run the libtcod samples c and c++ code in the 1.5.1 OSX download. However, the python sample gives me errors:

Traceback (most recent call last):

 File "", line 9, in <module>
   import libtcodpy as libtcod
 File "/Users/user/build/libtcod/", line 46, in <module>
   _lib = ctypes.cdll['./libtcod.dylib']
 File "/usr/local/Cellar/python/2.7.8_2/Frameworks/Python.framework/Versions/2.7/lib/python2.7/ctypes/", line 440, in __getitem__
   return getattr(self, name)
 File "/usr/local/Cellar/python/2.7.8_2/Frameworks/Python.framework/Versions/2.7/lib/python2.7/ctypes/", line 435, in __getattr__
   dll = self._dlltype(name)
 File "/usr/local/Cellar/python/2.7.8_2/Frameworks/Python.framework/Versions/2.7/lib/python2.7/ctypes/", line 365, in __init__
   self._handle = _dlopen(self._name, mode)

OSError: dlopen(./libtcod.dylib, 6): image not found

UPDATE UPDATE: Ok, the problem was that could not find libtcod.dylib. I changed the path in the script to fix that, and it seems to work. Hopefully that won't mess anything else up. If it does, I'll try copying the file from /usr/local/Cellar/libtcod/1.5.1/lib to my working directory. If no more issues come up, I'll erase this whole thing and put up a step-by-step on how I set this up.

UPDATE 3: I've been able run the tutorial code. The process was
1) Install HomeBrew at and then run "brew install libtcod"
2) Get ahold of joerumz OSX compile of libtcod 1.5.1 and extract it to your working directory. [I tried just copying some of the files as suggested in the tutorial, but gave up after several unsuccessful guesses. Copying everything seems to work.]
3) "make" the joerumz package including samples. Run the samples. You may need to copy them to the main working directory from their subdirectories in order for them to run.
4) Try running the python sample. If that doesn't work, you might need to modify so that it points to "libtcod.dylib" instead of "./libtcod.dylib"
5) If the samples work, you should make a copy of working directory for future projects. And then just write your code in the working directory and run.

I'm sure some of this is redundant, but is how I got it to work.

Thanks for documenting your process. It will be helpful to other OS X users.-Muscles (talk) 21:13, 3 November 2014 (CET)

error with libtcod 1.6.2 configure

Hello, I'm going through this tutorial on a fresh VM of Ubuntu 18.04.

I get through doing

autoreconf -i

for libtcod, but when I issue


I get several checks, ending in the following error:

checking whether the g++ linker (/usr/bin/ld -m elf_x86_64) supports shared libraries... yes
checking dynamic linker characteristics... (cached) GNU/Linux
checking how to hardcode library paths into programs... immediate
./configure: line 16662: syntax error near unexpected token `SDL,'
./configure: line 16662: `    PKG_CHECK_MODULES(SDL, sdl2 >= $min_sdl_version,'

I have tried this process several times, but keep running into this.

Any help would be appreciated! Thanks! :)