Difference between revisions of "Complete Roguelike Tutorial, using Python+libtcod, extras"

From RogueBasin
Jump to navigation Jump to search
(page created)
 
m (formatting)
Line 8: Line 8:
<center><h1>'''Extras'''</h1></center>
<center><h1>'''Extras'''</h1></center>


== A neat python shortcut for Notepad++ ==
== A neat Python shortcut for Notepad++ ==


Although Notepad++ is light and has many nice features, it can be tricky to set up a shortcut to quickly run your game and see any errors or debug output. After reading the docs on Run commands, you might try to open a console (cmd) that doesn't close after the problem runs so you can see debug output (/k), and using the path to the currently open file:
Although Notepad++ is light and has many nice features, it can be tricky to set up a shortcut to quickly run your game and see any errors or debug output. After reading the docs on Run commands, you might try to open a console (''cmd'') that doesn't close after the problem runs so you can see debug output (''/k''), and using the path to the currently open file:




Line 45: Line 45:




Just change "C:\whatever\debug_py.bat" to the full path of the bat file you created. To create that shortcut in notepad++ go to menu Run->Run..., paste that line into the textbox, then choose Save. No more problems, and the console closes automatically if there are no errors.
Just change "C:\whatever\debug_py.bat" to the full path of the bat file you created. To create that shortcut in Notepad++ go to menu Run->Run..., paste that line into the textbox, then choose Save. No more problems, and the console closes automatically if there are no errors.

Revision as of 19:26, 29 August 2010

This is part of a series of tutorials; the main page can be found here.


Extras

A neat Python shortcut for Notepad++

Although Notepad++ is light and has many nice features, it can be tricky to set up a shortcut to quickly run your game and see any errors or debug output. After reading the docs on Run commands, you might try to open a console (cmd) that doesn't close after the problem runs so you can see debug output (/k), and using the path to the currently open file:


cmd /k "$(FULL_CURRENT_PATH)"


You then may puzzle over the following error (or similar), which doesn't seem connected to Notepad++ at all:


WindowsError: [Error 126] The specified module could not be found


The problem is this: Notepad++ and Python are smart enough to run the file, but not smart enough to initialize the "current directory" to the file's directory. So when trying to load libtcod, Python looks for it in all the usual places except where you put libtcod. (Computers can be so thick sometimes!) The fix is to previously "change directory" there, which can be done with a batch file.

Here's my setup. I want to launch the file in a console, so I can see any debug output, and I wanna keep it around in case of errors (to see the traceback) but close it automatically if the program runs fine -- accumulating lots of console windows when there are no errors is annoying. (To explicitly "pause" the console even when there are no errors call the built-in function raw_input from your program.) I simply created a windows batch file debug_py.bat with this:


@echo off

cd %1
%2

if not errorlevel 1 goto quit
echo.
echo.
pause
:quit


Assuming parameter %1 is the file's directory, and %2 is the file name, this just changes to that dir and runs it, pausing the console if there's an error. The notepad++ shortcut that executes it with the correct parameters is this:


"C:\whatever\debug_py.bat" "$(CURRENT_DIRECTORY)" $(FILE_NAME)


Just change "C:\whatever\debug_py.bat" to the full path of the bat file you created. To create that shortcut in Notepad++ go to menu Run->Run..., paste that line into the textbox, then choose Save. No more problems, and the console closes automatically if there are no errors.