Activity: Wordsmith
A Minecraft world is full of creativity. In this activity, you will use variables to show your creativity with words. You will join two words together to create a new compound word. By using variables, you can store two words and then - in code - combine them. The cool part will be spelling out your new word in Minecraft.
Do the activity
Make a new project
Create a new MakeCode project and name it “Wordsmith.”
From
||loops:LOOPS||
, drag||loops:on start||
into the coding Workspace.Open
||variables:VARIABLES||
, and add||variables:set item||
inside||loops:on start||
.Click Advanced to see the
||text:TEXT||
Toolbox category. Select the||""||
and place this inside||variables:set item||
, replacing the number 0. You will set this variable to a string.Use the
||variables:set item||
drop-down list to renameitem
toword1
.
Right-click
||variables:set word1||
and duplicate it.Put this new duplicate in
||loops:on start||
.
You will need to make a new variable to store word2
. For this one, you cannot just rename it as you did before.
From
||variables:VARIABLES||
, click Make a Variable and name itword2
.Now go back to the second
||variables:set word1||
and changeword1
toword2
from the drop-down list.
let word2 = ""
let word1 = ""
word1 = ""
word2 = ""
Write two funny words!
Replace the empty
" "
with some text forword1
.Replace the empty
" "
with some text forword2
.
These words can be any appropriate words that mix well. For example, your first word might be “rail” for ||variables:word1||
, and your second word might be “road” for ||variables:word2||
.
let word2 = ""
let word1 = ""
word1 = "rail"
word2 = "road"
Print word1
From
||player:PLAYER||
, drag||player:on chat command||
into the Workspace. Name the commandmix
.From
||blocks:BLOCKS||
, drag||blocks:print||
to snap inside||player:on chat command mix||
.From
||variables:VARIABLES||
, put||variables:word1||
inside||blocks:print||
.Change the grass to Redstone Ore.
let word2 = ""
let word1 = ""
player.onChat("mix", function () {
blocks.print(
word1,
REDSTONE_ORE,
pos(0, 0, 0),
WEST
)
})
word1 = "rail"
word2 = "road"
Set up word2
As you have done many times, you can use duplicate
to speed up your build here. Knowing when to utilize duplicate
can really save you a lot of time.
Duplicate
||blocks:print||
||variables:word1||
.Change this so it prints
||variables:word2||
.Change the grass to Redstone Lamp.
Fine-tune and test
The coordinates shown in the following code work best and provide you with a nice spacing. You will notice that the Y value is a bit positive. You need to print in the air a bit to leave enough room for everything to fit.
Also, you started printing south on the north/south axis, so…
- Adjust the
||blocks:print||
so it readsalong South (positive Z)
.
let word2 = ""
let word1 = ""
player.onChat("mix", function () {
blocks.print(
word1,
REDSTONE_ORE,
pos(0, 0, 0),
SOUTH
)
})
word1 = "rail"
word2 = "road"
A problem
Your two words are now printing, but there is a little problem. If you don’t stop moving after typing mix, the two words will not be aligned when they print. In the following picture, you can see this little problem on the right.
Fix it: store your player’s world position
You can fix your problem by storing the player’s world position when you start to print.
From
||variables:VARIABLES||
, click Make a Variable and name the new variableStarting_World_Position
.From
||variables:VARIABLES||
, add||variables:set item||
to the top of||player:on chat command mix||
.Change this block to read
Set Starting_World_Position
.From
||player:PLAYER||
, put||player:player world position||
into||variables:set Starting_World_Position||
.
let word2 = ""
let Starting_World_Position: Position = null
let word1 = ""
player.onChat("mix", function () {
Starting_World_Position = player.position()
blocks.print(
word1,
REDSTONE_ORE,
pos(0, 30, 0),
SOUTH
)
blocks.print(
word2,
REDSTONE_LAMP,
pos(0, 20, 0),
SOUTH
)
})
word1 = "rail"
word2 = "road"
Fix the print block’s position
Now you want to use the stored world position and change the print block to use this number. The number will be the same, so you don’t have to worry about words getting misaligned.
- From
||positions:POSITIONS||
, drag the following block onto the work area:
This block allows you to add two coordinates together - it is perfect for your purposes. You can add on to the world position you stored before in Starting_World_Position
.
- Move stuff around and add things until you get code that looks like the blocks shown here:
let word2 = ""
let Starting_World_Position: Position = null
let word1 = ""
player.onChat("mix", function () {
Starting_World_Position = player.position()
blocks.print(
word1,
REDSTONE_ORE,
positions.add(
Starting_World_Position,
pos(0, 30, 0)
),
SOUTH
)
blocks.print(
word2,
REDSTONE_LAMP,
positions.add(
Starting_World_Position,
pos(0, 20, 0)
),
SOUTH
)
})
word1 = "rail"
word2 = "road"
Join and print
Finally, you are ready to join these two words together. Again, let’s call on our friend duplicate
!
Duplicate one of the
||blocks:print||
blocks and place it at the bottom of||player:on chat command mix||
.Adjust settings so that you print using
Block of Redstone
.The Y relative coordinate should be 5.
From the search bar, search for “join”. This is a
||text:TEXT||
block.Place this block so
||blocks:print||
readsprint join word1 word2
.
let word2 = ""
let word1 = ""
let Starting_World_Position: Position = null
player.onChat("mix", function () {
Starting_World_Position = player.position()
blocks.print(
word1,
REDSTONE_ORE,
positions.add(
Starting_World_Position,
pos(0, 30, 0)
),
SOUTH
)
blocks.print(
word2,
REDSTONE_LAMP,
positions.add(
Starting_World_Position,
pos(0, 20, 0)
),
SOUTH
)
blocks.print(
word1 + word2,
REDSTONE_BLOCK,
positions.add(
Starting_World_Position,
pos(0, 5, 0)
),
SOUTH
)
})
word1 = "rail"
word2 = "road"
Challenges
Now you can change some things to make your own different and unique situations!
Challenge 1 - Display a ‘+’ Sign to Make the Action Look Like a Math Problem
You are doing “word math” in this activity, so let’s complete the idea and theme this out! Add a plus sign to the left of the words at the top, just like you would if you were adding two numbers.
Challenge 2 - Add a Line to Finish the Math Equation Look
How could you draw a line under the two words to make it look just like a math problem?
Experiments
Here there are no rules… Copy the code for the experiments and change things around to see what kind of results you can create. Suggestions are given, but do as you like!
Experiment 1 - Flying Letters
Write some letters to birds with this code. A random letter from the alphabet is printed as you fly! Notice that the range is 0 through 25! That’s because this is zero-based… it starts with 0 as the first position.
How could you print only vowels? In what other ways could you use a random variable and text to create something?
Experiment 2 - Chopping Up Sentences
You can cut out portions of a string (text) to print.
Use this code to start with.
How could you print out two of these words at a time instead of just one? In what other ways could you use a random variable and text to create something? What about using a different sentence or maybe a paragraph?