Multiple .lua files, error handling and common functions
Posted: Thu Nov 03, 2016 11:46 pm
Before telling what my questions actually are, here's some explanation about the game I'm making:
- It's a card game, so there are common rules to every card, but they have their particular effects.
- Not every card needs a separate file for their effect, because some of them don't have any.
Now, what I need some help with:
1. I've been thinking of putting each card "code" in a file, containg all specific effects/conditions/rules. Running those files is easy, I just have to use require and keep it somewhere with the card id or in a table. If one of those files pop an error, the game stops, as expected, but that's not good, there should be a way to ignore the error, stop only that specific card from working, print that error in a log or something (to help debugging) and let the game move on. The abscence of a file should also be ignored. How can this be done?
2. Each card is unique, but they all obey a certain group of rules. These rules could be in another file to be run later, but is there a way to make these functions available to every card without using require on every single file?
Any advice or suggestion would be helpful Thank you
- It's a card game, so there are common rules to every card, but they have their particular effects.
- Not every card needs a separate file for their effect, because some of them don't have any.
Now, what I need some help with:
1. I've been thinking of putting each card "code" in a file, containg all specific effects/conditions/rules. Running those files is easy, I just have to use require and keep it somewhere with the card id or in a table. If one of those files pop an error, the game stops, as expected, but that's not good, there should be a way to ignore the error, stop only that specific card from working, print that error in a log or something (to help debugging) and let the game move on. The abscence of a file should also be ignored. How can this be done?
2. Each card is unique, but they all obey a certain group of rules. These rules could be in another file to be run later, but is there a way to make these functions available to every card without using require on every single file?
Any advice or suggestion would be helpful Thank you