BasicsTutorial/Data Statements

Last-modified: 2008-03-10 (月) 12:13:12

Data Statements

データ命令文

Now that we know how to use arrays to store information the only problem is assigning that information in a quick, easy and short way.
我々が情報を格納するために配列を使う方法を知っている今、唯一の問題は速くて、簡単で、短い方向でその情報を割り当てている。
Writing something like this…
このような何かを書くこと

Dim array(100)
array(1) = 10
array(2) = 75
array(3) = 917
array(4) = 0

All the way to…
全ての方法to…

array(100) = 73

Would take a while, as with reading data from arrays.
配列からデータを読むことと同様に、間をとる。
We can already use FOR_NEXT loops to read from arrays, now what if we could use them to WRITE to arrays.
我々が配列に書くためにそれらを使うことができた今、我々は配列から読むためにFOR_NEXTループをすでに使用することができる。
Well the DATA command is made for exactly that purpose.
よく、 DATA命令は、正確にその目的のために使われる。

`15 numbers stored with the data statement
Data 20, 10, 84, 103, 302, 39, 29, 7364, 0, 92, 92, 7352, 937, 81, 103
Dim numbers(15)
`Read and print all the numbers using an array
For x = 1 to 15
  Read numbers(x)
  Print numbers(x)
Next x
Wait key

Let’s look at the first line first.
最初に最初の行を見よう。
The DATA command is written, followed by a list of values separated by commas.
DATA命令は記述される。そして、コンマで区切られる値のリストが続く。
This is how a DATA statement is formed.
これは、そう、DATA命令文が作られる方法である。
The values are stored in memory waiting to be called with the READ_ command.
値は、READ命令で呼ばれるために待っている記憶に保管される。

The READ command reads the values into the variable of array slot specified.
READコマンドは、指定される配列スロットの変数に、値を読み込む。
It reads them in the order that they were stored with the DATA command.
それは、それがDATA命令にたくわえられ、それらを読む。
Imagine a conveyer belt, the first thing that goes on is the first thing that comes off, so in this case 20 is read first, then 10, then 84 and so on.
コンベヤーベルトを想像しなさい、続く最初のものは離れて、それで、20が最初に読まれるというこの場合、それから10、それから84その他で来る最初のものである。
When there is no more data to read the READ command fills the variable with a value of 0.
どんなデータも無いとき、READ命令を読むことは変数を0の値で満たす。

You can read in floats and strings as well, just make sure you read into the correct type of variable.
あなたは同様に浮動小数点と文字列を読み取ることができる、ちょっとあなたが変数の正しいタイプで読んだことを確認しなさい。
For example this won’t work.
たとえば、これは働かない。

Data “Hello”, “World”
Read intVar
Read floatVar

The type of data you are reading in needs to match the type of variable you are reading it to.
あなたが読んでいるデータの型は、あなたがそれを読んでいる変数のタイプにマッチする必要がある。

Another good thing about the DATA command, which confused me at first, is that you can place it anywhere in your code and even if the computer hasn’t passed that line it will still read the data into memory at the start.
(それは最初は私を混乱させた)DATA命令についてのもう一つの良いことはあなたがあなたのコードでどこにでもそれを置くことができるということである、そして、たとえコンピュータがその台詞を伝えなかったとしても、それは初めは記憶にデータをまだ読む。
For example you could change the code above to be…
たとえば、あなたはコード上で変えることができた

Dim numbers(15)
`Read and print all the numbers using an array
For x = 1 to 15
  Read numbers(x)
  Print numbers(x)
Next x
Wait key
`15 numbers stored with the data statement
Data 20, 10, 84, 103, 302, 39, 29, 7364
Data 0, 92, 92, 7352, 937, 81, 103

And that will still work.
そして、それはまだ働く。
Also notice how I separated the DATA statement onto two lines this time.
また、私がどのように今度は2本の行の上へDATA命令文を切り離したかについて気がつきなさい。
That helps with keeping the data readable.
それは、データを読みやすくしておくことを手伝う。
It’s also good if you separate DATA statements where there is a change in types of data, or the category of your data (how it is used in your program).
データの型の変化またはあなたのデータ(なんて、それがあなたのプログラムで使われるだろう)のカテゴリーがある所であなたが DATA命令文を切り離すならば、それはよくもある。

`Name and cost of car in credits
Data “Ferrari”, 1000, “Mini”, 100, “Porsche”, “800”
`Name and number of points needed to unlock level
Data “Desert”, 100, “City Centre”, 200, “Racing Course”, “450”
`Character name and stats (skill, recklessness, style)
“Bob”, 4, 9, 9, “Michelle”, “7, 2, 10”, “Al”, 8, 8, 6

That would be for some sort of a driving game, but I separated the car, level and character data onto different lines to keep things orderly.
それはある種の運転ゲームに賛成である、しかし、私はものを整然としておくために異なる行の上へ車、レベルとキャラクタ・データを切り離した。
It’s also handy to remark DATA statements well because it can be very confusing coming back to a list of numbers after a couple of months.
二ヵ月後に数のリストに戻ることが非常に混乱させることがありえるので、よくDTATA命令文を述べることは、便利でもある。
Ordered code is the most important thing in programming (along with code that works ;D ).
手順に沿ったコードは、プログラミングで最も重要なものである。(働くコードに加えて;D)

OK, so you’ve read your data in to an array, but what if you wanted to read your data in again?
OK、あなたが配列(あなたが再びあなたのデータを読み取ることを望んだもしも以外の)にあなたのデータを読み取ったように?
Yes you COULD use the DATA command and store them twice, but that would be unnecessary and make your code long.
はい、あなたはDATA命令を使うことができて、二回それらを保存することができた、しかし、それは不必要で、長くあなたのコードを製作する。
Instead use the RESTORE command.
その代わりに、RESTORE命令を使う。

Dim numbers(15)
Dim numbersAgain(15)
`Read and print all the numbers using an array
For x = 1 to 15
  Read numbers(x)
  Print numbers(x)
Next x
Restore
Print
Print “NUMBERS AGAIN”
`Read and print all the numbers using an array
For x = 1 to 15
  Read numbersAgain(x)
  Print numbersAgain(x)
Next x
Wait key
`15 numbers stored with the data statement
Data 20, 10, 84, 103, 302, 39, 29, 7364
Data 0, 92, 92, 7352, 937, 81, 103

The RESTORE command reads all the data from all the DATA statements in your code into memory again, starting from the top of your code.
RESTORE命令は、あなたのコードのトップから始まって、再び記憶にあなたのコードで全ての DATA命令文から全てのデータを読む。
Any previous data that was stored in memory is deleted.
どんな前のデータでも、メモリーに保管されたものは削除される。

The RESTORE command also has an optional parameter where you can put the name of a label.
RESTOR命令にもあなたがラベルの名前を置くことができるオプションのパラメータがある。

Dim numbers(15)
Dim numbersAgain(7)
`Read and print all the numbers using an array
For x = 1 to 15
  Read numbers(x)
  Print numbers(x)
Next x
Restore dataLabel
Print
Print "NUMBERS AGAIN"
`Read and print all the numbers using an array
For x = 1 to 7
  Read numbersAgain(x)
  Print numbersAgain(x)
Next x
Wait key
`15 numbers stored with the data statement
Data 20, 10, 84, 103, 302, 39, 29, 7364
dataLabel:
Data 0, 92, 92, 7352, 937, 81, 103

If you use this command the data, instead of being read from the top of the code down, is read from the position of the label down.
あなたがこのコマンドを使用するならば、データは、下ってコードのトップから読まれる代わりに、ラベルの位置から読まれる。
In this case 0 is first after the label ‘dataLabel’ and is the first command read off into the array.
この場合、0はラベル『dataLabel』の後、最初で、配列に読みとられる最初の命令である。

Summary of Commands

命令の概要

· DATA data1[,data2 [,data2[,….]]] - Stores a list of data into memory ready to be called with the READ command.
DATA data1[data2[data2[…。]]]- READコマンドで呼ばれる準備ができているメモリーに、データのリストを格納する。

· READ var - Reads the data stored by the DATA command into a variables, in the order it was stored.
READ 変数 ― 変数に DATAコマンドによって格納されるデータが読む。 それは保存された順序で。

· RESTORE [label] - Resets the data stored by the DATA command from the top of the code, or the label optionally specified.
RESTORE [Lable] – DATAコマンドから読み込む場所を指定する。ラベルが無ければ最初から、ラベルがあればラベルの位置から読み込む。

End of Section Tasks

セクション終わりの作業

l Write a program that reads the size and position of 4 squares into a multidimensional array, and draws the square specified.
多次元配列にサイズと4つの正方形の位置を読み込んで、指定される正方形を描くプログラムを記述しなさい。
Once the square is drawn you should give the option to go back and select another square or quit.
一旦正方形が描かれるならば、あなたは戻って、もう一つの正方形を選ぶためにオプションを伝えなければならないか、やめなければならない。