Auto-translated
Alex, there are several approaches you can take:
Write scripts in editors with syntax checking, such as the HoMM5 MapScriptsEditor. At the very least, it will immediately issue warnings for minor typos, plus it offers autocompletion of function names and parameter hints (although this feature works somewhat glitchily).
Comment out the entire script code, then uncomment it in small chunks, a few lines at a time, and check if it works, or fix it until it does, and only then move on to the next chunk. You can mark the parts that are already working in some way so that you don't have to check them again next time.
Place test debug messages in the code, such as print('this function has been executed'). This makes it easy to see which section of code has been executed and which has not.
A particularly useful trick is to debug the code without leaving the game. Create a .lua file in Unicode encoding in the "path_to_heroes/data" folder, write the code you are unsure about in it, and you can add something like print('script OK') at the end of the file. Load the map, open the console, and type doFile('filename.lua'). If you see the green message 'script OK' in the console, the code is working; if not, close the game, work on the file, don't forget to save, go back to the game, and enter the same command in the console (you can just press the up arrow button). Repeat until the code works.
Write scripts in editors with syntax checking, such as the HoMM5 MapScriptsEditor. At the very least, it will immediately issue warnings for minor typos, plus it offers autocompletion of function names and parameter hints (although this feature works somewhat glitchily).
Comment out the entire script code, then uncomment it in small chunks, a few lines at a time, and check if it works, or fix it until it does, and only then move on to the next chunk. You can mark the parts that are already working in some way so that you don't have to check them again next time.
Place test debug messages in the code, such as print('this function has been executed'). This makes it easy to see which section of code has been executed and which has not.
A particularly useful trick is to debug the code without leaving the game. Create a .lua file in Unicode encoding in the "path_to_heroes/data" folder, write the code you are unsure about in it, and you can add something like print('script OK') at the end of the file. Load the map, open the console, and type doFile('filename.lua'). If you see the green message 'script OK' in the console, the code is working; if not, close the game, work on the file, don't forget to save, go back to the game, and enter the same command in the console (you can just press the up arrow button). Repeat until the code works.