The Most Important Line of Code in Obscurity
I want to preface this post by saying that if you are an experienced programmer, or even a non-beginner, then this post won't have anything for you. Frankly, what I'm sharing is something I should have learnt a long time ago. But if you, like me, tend to do things the stubborn way you know rather than learning the better ways to go about something, then this may be of some use to you.
One of the very first things created for Obscurity is the throwable disappearing blocks. It was a bit of spaghetti code whipped up in an hour, and every time and error showed up I'd slap a bandage on it and hope it held together until the next bug. When the cubes destroyed themselves, and then new ones had to respawn in their place there were errors for sure, but I put some little fixes in and moved on. Once the repulsion cubes were added, along came more errors and it got to the point where enough was enough. I had to rewrite the cube code from scratch, and do it right this time. That's where I learnt of the most important piece of code in obscurity:
This little if statement here is a life saver. What happens when a cube is destroyed but the code is still looking for something to do with it? It crashes, obviously, but in my case I put all sorts of arbitrary checks about if the cubes have been spawned, or picked up, or thrown or all manner of things, when all I needed was that little snip of code there. If the object exists, then run the code for it.
In hindsight it should've been very obvious, and I feel pretty stupid for not doing it sooner. It's definitely something I'll be using in EVERY project I do going forward. So if you yourself are a beginner programmer, or just as stubborn in your "tried and true" methods as I am, then just keep this in mind for your next project. Checking if the object your code is affecting actually exists before telling it what to do can save so many headaches, as well as lines of code.
Get Obscurity
Obscurity
Status | In development |
Authors | Fire Noodle, Synthware |
Genre | Puzzle |
Tags | Relaxing, Singleplayer |
More posts
- Texturing and ConceptsAug 25, 2024
- An Iterative ProcessAug 20, 2024
- Michael Cardoso on Stories within ObscurityAug 15, 2024
- New blog post week 10Aug 08, 2024
- Sounds of ObscurityJul 25, 2024
- New Dev blogJul 21, 2024
- Second blog postJul 13, 2024
- First Dev BlogJul 07, 2024
Leave a comment
Log in with itch.io to leave a comment.