Arrays in Minecraft

Information
Step 1
Arrays
Temp1548368975

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
load("scriptcraft/modules/bukkit/master.js");
Temp1548369142
Step 3
Create an empty array

Use [ ] to create an array

Temp1548369215
Step 4
Add a story between your [ ]

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

Temp1548369544

You can write any story you want

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

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!

Temp1548370599
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

Temp1548370815
Check Your Work
Step 11
A single sentence displayed
Temp1548370868
Challenge
Step 12

Change sentenceNum to display a different message

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

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
Temp1550009689
Check Your Work
Step 17
Your story should now reset
Temp1550009902
Planning
Step 18
Arrays of Buffs
Temp1550010269
Information
Step 19
There are a large number of potion effects in Minecraft
Temp1550010343
Challenge
Step 20
Create an array of Buffs

Use the information above to choose any number of effects

Temp1550010592 Temp1550010642
Step 21
Create a function to apply one of these powerups
Temp1550010786
Step 22
Apply the buff to the player calling the function
Temp1550011430
Check Your Work
Step 23
Buffs
Temp1550011015 Temp1550011030


Temp1550011049 Temp1550011064
Step 24
Make sure the number corresponds to a valid effect
Temp1550011650
Check Your Work
Step 25
Temp1550011721 Temp1550011750
Step 26
Create a random power up function
Temp1550011943
Step 27
Temp1550012029
Step 28
Temp1550012103
Step 29
Temp1550012178
Challenge
Step 30
Apply the buff in the slot of powerUpNumber in the buffs array
Temp1550012318
Check Your Work
Step 31
Temp1550012501
Step 32
Apply all power ups
Temp1550012667
Challenge
Step 33
Add each buff using the following loop and powerUpNumber
Temp1550012796
Check Your Work
Step 34
Temp1550012847
Arrays in Minecraft Info

Account

MVCode Clubs

Created By

Missing tiny jake wheaton

Course:

Fundamentals in Minecraft

Access Level

premium

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