How to make a debug mode?

Started by MichaelNG789, June 21, 2018, 04:11:57 AM

Previous topic - Next topic
I wanted to make a small debug mode in my quest. If you press a certain key, (in my case "m") you can press for example the number keys to get more hearts on the spot. I was thinking that I would use this in game_manager since I need the datatype "game" for "game_set_life(number)." I was trying to use a boolean with debug_mode being a variable and pressing "m" if debug_mode is true allows the extra commands, and the opposite as well to turn off debug mode, but it wasn't working for me. How could I do this?

Maybe post the code you have to make it easier to understand what you've done and where it isn't working. I also think the Solarus team has a debug mode code in some of their games, maybe look through their GitHub.

I think, even if you're not using game manager, the code sol.get_game = game might work to give you that data. But the main idea is to use game:on_key_pressed(key), and then if key == m, do your code. It might be quicker to code one key that adds a heart, then one key that subtracts a heart, rather than using the number keys. Plus then you could go above 9 hearts this way.

We did it with a simple file (empty) called debug, in the saves folder. We check if the file is present. You can look in our games like Mercuris Chess for more info.