Let's get sorting

8
Official Construct Team Post
Laura_D's avatar
Laura_D
  • 12 Jun, 2020
  • 262 words
  • ~1-2 mins
  • 1,043 visits
  • 6 favourites

Happy Friday! Today I'm gonna talk about arrays some more, hurrah!

So the inventory is now sortable thanks to the Sort action that comes with the array plugin. When you add items to the inventory, they just get added onto the back of the axis, which is great but when you get more than a few items, it can be nice to sort your items.

I've gone with a simple alphabetical sort in this example, so first thing I did was to rearrange the JSON file I'm using to store all the info for the items. Now, the items in the JSON are listed in alphabetical order, and their IDs adjusted to match.

Then, I added the following event to the project – to allow me to sort the inventory when it's open by pressing the S key:

Now, the Y axis will be sorted in numerical order, which thanks to the updated JSON file, is now in alphabetical order too. So, depending on how you arrange your JSON, you could sort your arrays in all kinds of ways.

Also, have this screenshot because the inventory actually looks like what it's supposed to be. Not very pretty, but hey at least it resembles an inventory.

And as a final note, I've actually started drafting up the text and getting all the comments in for the working parts of the project, so the tutorial for this inventory is starting to come together. Fair warning, it's going to be a mammoth of a tutorial as there's so much to talk about!

Subscribe

Get emailed when there are new posts!

  • 2 Comments

  • Order by
Want to leave a comment? Login or Register an account!