owned this note
owned this note
Published
Linked with GitHub
###### tags: `minecraft`
<style>
* {font-family: 'Terminal','ヒラギノ丸ゴ ProN','Hiragino Maru Gothic ProN',YuGothic,'Yu Gothic','Hiragino Kaku Gothic ProN','ヒラギノ角ゴ ProN W3','Verdana','Arial',sans-serif;}
.markdown-body {font-family: 'Terminal','ヒラギノ丸ゴ ProN','Hiragino Maru Gothic ProN',YuGothic,'Yu Gothic','Hiragino Kaku Gothic ProN','ヒラギノ角ゴ ProN W3','Verdana','Arial',sans-serif;}
h2 {padding-top: 50px;}
img {margin: 20px auto;}
.alert-success {margin-top: 50px;}
.alert h2 {padding-top: 0px;}
.part {letter-spacing: .1rem;}
.markdown-body h3 {margin-top: 12px;margin-bottom: 12px;}
.markdown-body p {font-size: 1.25em;margin-top: 12px; margin-bottom: 16px;}
.markdown-body li {font-size: 1.25em;}
.markdown-body pre {font-size: 20px;}
.focus {color: red;font-weight: bold;}
.link-box {display: flex;justify-content: space-between; margin-top: 50px;margin-bottom: 50px;}
a.link {display: block; width: 50%; padding: 10px 15px; text-align: center; color: #fff; font-weight: bold; font-size: 20px; letter-spacing: .1em; text-decoration: none;}
a.link:hover {opacity: 0.85;}
a.prev {background: linear-gradient(to bottom, #1A7BBD 0%, #1A7BBD 50%, #125684 51%, #125684 100%); border-radius: 10px 0 0 10px;}
a.next {background: linear-gradient(to bottom, #D76820 0%, #D76820 50%, #964816 51%, #964816 100%); border-radius: 0 10px 10px 0;}
</style>
> [name=shinya kunisada]
# 【第15回】 アイテムを比べてみよう!
:::success
### 【今回の目標】
- ### ブロックやアイテムの種類を比べよう!
- ### さいくつプログラムにフィルター機能をつけよう!
- ### 決まったアイテムだけを捨てよう!
:::
## ◆ いろいろなブロックやアイテム

### マインクラフトに登場するたくさんのブロックやアイテムを比べてみよう!
## ◆ 目の前のブロック(アイテム)をくらべる
### <span class="focus">turtle.compare()命令</span>で目の前のブロックと、選択されているスロットのアイテムを比べるよ!

### turtle.detect()命令と同じように、<span class="focus">true</span> または <span class="focus">false</span> が変数の中に入るよ!

## ◆ 目の前、上、下
### turtle.compare()命令には3種類あって、それぞれ
- ### <span class="focus">turtle.compare()</span> 目の前のブロックを比べる
- ### <span class="focus">turtle.compareUp()</span> 真上のブロックを比べる
- ### <span class="focus">turtle.compareDown()</span> 真下前のブロックを比べる
### といった使い分けができるんだ!
:::success
## 【課題1】 真下のブロックを比べよう!
:::
### スロットの1番目のアイテムと、<span class="focus">真下</span>のブロックを比べてみよう!
### ブロックが同じ場合は <span class="focus">true</span>、違った場合は <span class="focus">false</span> を表示させてみよう!

:::success
## 【課題2】 さいくつプログラムを改良
:::
### <span class="focus">スロットの1番目のブロックと同じブロックだけ掘る</span>ようにしよう!

### ただし、<span class="focus">真下に掘り進む時はどのブロックでも掘る</span>ようにしよう!

## ◆ 持っているアイテムを比べる
### <span class="focus">turtle.compareTo()命令</span>で、持っているアイテムどうしを比べることができるよ!

### <span clss="focus">いま選択されているスロットのアイテム</span>と、<span class="focus">かっこの中で指定したスロット番号のアイテム</span>を比べることができるんだ!
:::success
## 【課題3】 持ち物を比べてみる
:::
### スロット1番目と2番目のアイテムを比べて、<span class="focus">true</span>か<span class="focus">false</span>で表示しよう!

:::success
## 【課題4】 スロット1番目とそれ以外のアイテムを比べる
:::
### <span class="focus">for文</span>を使って、スロットの1番目のアイテムとそれ以外のスロットのアイテムをそれぞれ比べて、その結果を表示しよう!

:::success
## 【課題5】 特定のアイテムだけを捨てたい
:::
### 持っているアイテムの中で、<span class="focus">スロット1番目で指定したアイテムだけ(スロット1番以外)を捨てる</span>ようにしよう!

### この課題で必要な命令は
- ### <span class="focus">turtle.select()</span> スロットを選ぶ
- ### <span class="focus">turtle.compareTo()</span> アイテムを比べる
- ### <span class="focus">turtle.drop()</span> アイテムを捨てる
### の3つだよ!
### <span class="focus">if文</span>と<span class="focus">for文</span>も使うよ!!
<div class="link-box">
<a href="https://hackmd.io/CU6upwk_QROe_4P1EncGwA" class="link prev">前に戻る</a>
<a href="https://hackmd.io/eVSdho_-QXa1OlPumsUrBQ" class="link next">次に進む</a>
</div>