Game assert statement
I use statements like this to check conditions for some routine to work:
That is, if someone’s inventory is empty, the whole routine cannot be executed, so we skip it. But they’re just taking place (each one 4 lines at least) and are all pretty much following the same pattern, so they could be replaced with one function call like this:
Return statement could not be used there, but exeception throwing works pretty much the same way: it breaks execution flow and correctly destroys all local variables. And it could carry data like message text, which can be displayed when exception is catched. So full game_assert
function looks like this:
Disadvantage of this way it that one really need to enclose all code that calls such functions in try..catch block.