Safehou-se (Pt 6)
Home✗BlogI like how I titled my previous post the final update and yet here I am again with another Safehou-se feature... this time, I've added if variables to the mix. I also did a slight refractor of how I created templates, making it recursive and easier to add new features in the future.
Recursion...
While before I simply iterated through the string character by character (a painstaking process...), I now recursively call a function that turns a string into the list of variables I need. This fixed a few prior bugs I had as well:
- Including a global variable for the first time in a loop would make the variable not show up
- I simply could not add in other
Variable
types (not a bug... just inconvenient)
I ran into a few issues when doing my recursion, the biggest of which was Maximum call stack size exceeded
. This was because I would call the function on every. Single. Character. I quickly added in a quick if statement to essentially find the next variable if the start of the string given was not a variable and the error went away.
If Variables
Adding in if variables was a lot easier than expected. While I did have some issues with debugging, for the most part, it was quite simple to add in one more if/else branch to every function to check if the variable was an IfVariable
type (checked using the key signatures... although it would've been safer to use type-checking... this was an easier implementation).
Other than my constructor, all my other functions were already recursive, so it didn't take that much time. I did have to make quite a few modifications to the form generator, but all in all, this was a quick update.
Another minor issue came up with global variables, as global variables could not previously be used in loops, but can be nested inside of if statements. I spent way too long debugging this simple problem... I simply forgot that I had hard-coded in a %}}
variable ending. Changing it to simply }}
fixed it.
Upcoming
I probably won't make another blog post for it, but I still need to fix up on error message handling.