r/roguelikedev • u/OkMarket2217 • Mar 17 '26
Error code in the roguelike tutorial
Hey guys! I am getting an error code for “tileset=tileset” and I am not sure why. I am only on part 2 of the tutorial and have been fixing other error codes I received earlier. Would anyone be able to help?
15
u/HexDecimal libtcod maintainer | mastodon.gamedev.place/@HexDecimal Mar 17 '26
This code should all be inside the main function, but I can clearly see that you've dedented after tileset was assigned and put everything after it on the top-level.
Select event_hander = ... and everything up to before if __name__ == "__main__": and press tab to indent that whole section. Only if __name__ == "__main__": should have no indentation.
-22
u/lovecMC Mar 17 '26
Bit off topic but I don't get how people can defend indentation being part of syntax when it leads to things like this.
"But any IDE will catch it" - the utterly deranged
11
u/HexDecimal libtcod maintainer | mastodon.gamedev.place/@HexDecimal Mar 17 '26
Their IDE actually did catch it.
tilesetwas underlined indicating/warning thattilesetwas not set before it was used, but they didn't understand why.Misplaced brackets cause similar issues so I have no problem defending indentation as syntax. Especially since I use One True Brace style anyways.
10
u/trxxruraxvr Mar 17 '26
when it leads to things like this.
It doesn't lead to things like this if you know the language. In C the same thing happens when you remove a }. You wouldn't do that if you know the language, but beginners are going to make mistakes in any language..
4
u/dcpugalaxy Mar 17 '26
Indentation being part of syntax makes this incredibly obvious IF YOU HAVE EYES.
12
u/ordineu Mar 17 '26
This is Python, so the amount of space before each line matters. If I recall correctly, this part of the code is all supposed to be part of the main() function, so every line past that should be one tab forwards. I see that you stop tabbing things after tileset = tcod.tileset.load_tilesheet() -- just add a tab before the "event_handler =" and "with tcod.context" lines (and fixup the spacing on line 20 and 34) and it should be fixed.
7
0
2
u/oddtwang Mar 17 '26
Looks like everything needs to be indented so that it's within the scope of the main() definition; when you're running the program currently it's referring to a variable called tileset which hasn't been set because the main() function ends a couple of lines above and hasn't been run
0
u/ekim_axeman Mar 17 '26
The error is most like because the second instance of the word "tileset" is looking for a previously defined global variable of the name "tileset". Since you haven't provided it, the compiler is confused. Put your tileset definition before that line and it'll be ok!
2
u/OkMarket2217 Mar 17 '26
Update, this is now working and I am able to love on to part 2. Thank you again