The Refactoring Game: Functions and Expressions Edition!

5
Official Construct Team Post
Laura_D's avatar
Laura_D
  • 29 May, 2020
  • 368 words
  • ~1-2 mins
  • 916 visits
  • 1 favourites

Happy Friday, time for another progress report! Sorry these blog posts are getting a little samey – I’ve kinda slowed up with developing this purely because getting my brain to function correctly is a bit of a challenge these days!

The inventory is still coming along nicely though. I’ve started refactoring the original category code to make it more efficient – adding expressions and more functions to get rid of some of the duplicate events. It’s already looking better and feels nicer to use.

For example, I’m now using an expression which uses the size of the array to figure out how many pages it needs to display all of the items. And there’s a new function we can call to see if the pages need updating when adding new items to the inventory. Plus, you can now use a pair of keys to switch categories without having to scroll through all of the pages. There’s still plenty to do though as even now, going through my events my mind is constantly going “Hmm, there must be a better way to do that.” Kinda proud that I’ve gotten far enough with Construct to actually re-assess my own work like this!

So, while tidying isn’t the most exciting job, it’s definitely a good thing to do!

The next thing to sort out is making sure each category can act independently and we can update/use them individually. And a bit more work needs doing on the scrolling – replacing a constant with the new expression and making sure when you switch categories by scrolling, the correct page is loaded in the new category.

This is probably a more complicated example than it really needs to be, but there are several other inventory examples out there which are a little less complex than this one and I want to make sure this one is suitably different – so I’m not quite re-inventing the wheel. Or at least, if I am re-inventing it, I’m doing it for a good reason! I mean, it'll be used in my own game project, so that's something, but still - a usable tutorial is the main goal currently.

Anyway, have a good weekend wherever you are!

Subscribe

Get emailed when there are new posts!

  • 3 Comments

  • Order by
Want to leave a comment? Login or Register an account!
  • Refactoring may not be glamorous but it's an important part of development.

    This article codecademy.com/articles/tdd-red-green-refactor talks about the 3 stages of test driven development, but in practice even if you aren't using tests it helps to follow these 3 steps:

    1. Consider what it should do.

    2. Build something that matches that.

    3. Consider how to improve it.

    It's not uncommon to follow only the first 2 steps, but without step 3 those first 2 steps will get progressively more difficult!

    So try not to feel bad about not adding anything new, refactoring is equally important!

  • Bueno esta bien gracias

  • :T

    oki-dokie