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]
# 【第5回】 タートルに話を聞いてもらう
## ◆ 対話画面
ここでエディタ画面を呼び出したり、プログラムを実行したね!
今日はこの対話画面でタートルに話しかけてみるよ!

:::success
## ◆ 今回の目標
- ### スロット番号を話しかけて、選んでもらおう!
:::
## ◆ タートルに話かける

<span class="focus">io.read()命令</span>で、タートルが話を聞いてくれるよ!

## ◆ 聞いた内容を変数に入れる
<span class="focus">変数 = io.read()命令</span>で、話しかけた内容を変数に入れることができるよ!
```lua=
kaiwa = io.read()
# kaiwaという変数に、話しかけた内容や文字が入る
```
## ◆ キーボードで話かける
<span class="focus">キーボードで文字や数字を打ち込んで</span>話しかけるよ!
```lua=
> kaiwa -- io.read()を使うと
-- ここに話しかける内容を入力できる
```
## ◆ 課題
## ◆ 変数に入るのは文字
io.read()命令で入力した値は変数に<span class="focus">文字</span>として入ることに注意!
例えば<span class="focus">30</span>と入力したとき、変数に入るのは文字としての30だから、数字のように足し算や、かけ算のような計算はできないんだ!

## ◆ エラーで動かない
プログラミングしていると、どうしても数字として使いたいときがあるから、ちゃんと数字に変換してあげよう!
入力した値を数字として使いたいときは<span class="focus">tonumber()命令</span>で文字を数字に変えて使おう!

## ◆ 課題1
数字を入力して、<span class="focus">その数字のスロット番号を選んでもらおう</span>!
## ◆ 課題2
数字を入力して、<span class="focus">その数字だけ石炭をねん料にしよう</span>
## ◆ 課題3
課題の1と2を組み合わせて、<span class="focus">スロット番号もねん料の数も話しかけて決められる</span>ようにしよう
## ◆ 便利なワザ
ここで少し便利なワザを教えるよ!
## ◆ プログラムなしで燃料を入れる
<span class="focus">refuel allコマンド</span>で、ねん料を入れることができるよ!
<span class="focus">refuel all</span>はコマンドだから、プログラムを作らずに対話画面でそのまま実行することができるよ!

できたかな?
<!-- <div class="link-box">
<a href="#" class="link prev">◀︎ 前の内容に戻る</a>
<a href="#" class="link next">次の内容に進む ▶︎</a>
</div> -->