Jump to content
Miguel Preguisa

Arrays - how do they work?

Recommended Posts

I'm slowly learning about all kinds of different game logic components (thanks to @Igor Q. tutorials too) and I got a feeling that arrays could be really useful. But I don't see where are the situatios that arrays are made for. I tried to look up what are they used for but all I understood (hopefully) is that they somehow "group" objects like variables or entities, vectors etc. Is there anybody willing to ELI5 to me? 🙂 

Share this post


Link to post
Share on other sites

Arrays are similar to basic variables but for storing multiple pieces of information.

Ex: When player spawns, add player to array "Total player list". Make a scoreboard using each player from the "Total player list".

It's often useful when you want not only to store a list but change it's information later on.

If you check out the script I made Global chest, it uses an array to store inventory slots of a chest and then saves/loads that information when a player uses a chest.

  • Thanks 1

Share this post


Link to post
Share on other sites
1 hour ago, Igor Q. said:

If you check out the script I made Global chest, it uses an array to store inventory slots of a chest and then saves/loads that information when a player uses a chest.

Definitely going to do that! It's true that I haven't seen this piece yet. Array than seems to be like a dynamic list, that could really simplify some of my code full of variables 🤔 Thank you! 

Share this post


Link to post
Share on other sites
10 hours ago, Miguel Preguisa said:

I'm slowly learning about all kinds of different game logic components (thanks to @Igor Q. tutorials too) and I got a feeling that arrays could be really useful. But I don't see where are the situatios that arrays are made for. I tried to look up what are they used for but all I understood (hopefully) is that they somehow "group" objects like variables or entities, vectors etc. Is there anybody willing to ELI5 to me? 🙂 

just to add on a bit to what igor said they are basically a list of variables each item in the array has a number. The numbers(known as the index) start from 0 so the first item will have index 0, second item will have the index 1 ect. Defintly check out the wiki for the array functions

Edited by Oliver Hope
  • Thanks 1

Share this post


Link to post
Share on other sites
9 minutes ago, Oliver Hope said:

just to add on a bit to what igor said they are basically a list of variables each item in the array has a number. The numbers(known as the index) start from 0 so the first item will have index 0, second item will have the index 2 ect. Defintly check out the wiki for the array functions

Thank you too! In learning the Editor, there's never too much. Too bad I won't have access to it the whole next week, we are going skiing, but I would love to test all the different ideas in my head right now  :D

PS: I believe there is a typo, isn't there? "... the first item will have index 0, second item will have the index 2..." shouldn't then the second one have the index 1? 

Share this post


Link to post
Share on other sites
32 minutes ago, Miguel Preguisa said:

Thank you too! In learning the Editor, there's never too much. Too bad I won't have access to it the whole next week, we are going skiing, but I would love to test all the different ideas in my head right now  :D

PS: I believe there is a typo, isn't there? "... the first item will have index 0, second item will have the index 2..." shouldn't then the second one have the index 1? 

Enjoy your skiing!

yes I did make a type, just edited it😋

 

  • Like 1

Share this post


Link to post
Share on other sites

Please sign in to comment

You will be able to leave a comment after signing in



Sign In Now

×