Arrays in Minecraft

Step 1

An Array is a collection of variables

We can use arrays to:

  • Create a sequence of actions or items
  • Apply code to a set of creatures or items
  • Create a pool of random options

Step 2
Load in Scriptcraft libraries
Step 3
Create an empty array

Use [ ] to create an array

Step 4
Add a story between your [ ]

Each piece of your story must be surrounded by " and end with a ,

You can write any story you want

Step 5
Create a function to output our story
Step 6
Add an echo to output our story
Check Your Work
Step 7
The whole story
Step 8
One piece at a time

We want to display the story one piece at a time

To do this we will create a control variable

Step 9
Create a control variable

sentenceNum will keep track of our place in the story!

Step 10
Update the storyTime function

we use [ ] after story to tell it which piece of the story to display

in this case sentenceNum is 0, so we will display the first element

Check Your Work
Step 11
A single sentence displayed
Step 12

Change sentenceNum to display a different message

Step 13
Reset sentenceNum and make it increase after each time you call the function
Check Your Work
Step 14
Each time you execute the function, it should display a new message!
Step 15

Once we reach the end of the story, the values in the array are undefined

We will fix this by resetting sentenceNum

Step 16
Restart the story
Check Your Work
Step 17
Your story should now reset
Step 18
Arrays of Buffs
Step 19
There are a large number of potion effects in Minecraft
Step 20
Create an array of Buffs

Use the information above to choose any number of effects

Step 21
Create a function to apply one of these powerups
Step 22
Apply the buff to the player calling the function
Check Your Work
Step 23

Step 24
Make sure the number corresponds to a valid effect
Check Your Work
Step 25
Step 26
Create a random power up function
Step 27
Step 28
Step 29
Step 30
Apply the buff in the slot of powerUpNumber in the buffs array
Check Your Work
Step 31
Step 32
Apply all power ups
Step 33
Add each buff using the following loop and powerUpNumber
Check Your Work
Step 34
Arrays in Minecraft Info


MVCode Clubs

Created By

jake wheaton


Fundamentals in Minecraft

Access Level


For Teachers and Schools

Teach coding to your students with MVCode Teach

MVCode offers an integrated product designed to teach coding to students.

Learn more about MVCode Teach