BasicsTutorial/User defined types

Last-modified: 2009-01-13 (火) 16:28:07

User defined types

ユーザー定義されたタイプ

User defined types are mighty handy things, basically they are variables that can be split up into many different sub-variables to store many different values.
ユーザー定義済みのタイプは強力な便利なものである、基本的に、それは多くの異なる値を保存するために多くの異なる下位変数に分けられることができる変数である。
Kind of like a customizable array.
カスタマイズ可能な配列がちょっと似ている。
For example, instead of having the variables…
たとえば、変数を持つ代わりに、

例、ジョンさんの情報

johnName
johnGender
johnAge
johnTelephone
johnHeight

We would have…
我々はそうする…

John.name
John.gender
John.age
John.telephone
John.height

Now this may seem a bit pointless, but we actually only have to declare one variable once we have set up the sub variables.
現在、これは少し無意味なようかもしれない、しかし、一旦我々が下位変数を準備するならば、我々は実はひとつの変数を宣言するだけである。
First we have to set up the type…
最初に、我々はtypeを準備しなければならない

 type userType
  name as string
  gender as boolean
  age as byte
  telephone as integer
  height as float
 endtype
 john as userType

This snippet would be placed at the top of your code.
この断片は、あなたのコードの最上部で置かれる。
You start the type using the TYPE command with the name of your type after.
あなたは、タイプを後にあなたのタイプの名前でTYPE命令を使わせ始める。
This can be anything, I tend to put “type” at the end of the type name so I can recognise it as a type, and you end it using ENDTYPE.
これは何ででもありえる、私がそれをタイプと認めることができるように、私はタイプ名の終わりに「Type」を置く傾向がある、そして、あなたはENDTYPEを用いてそれを終える。
In between these two commands you put a series of variables.
これらの2つの命令の間に、あなたは一連の変数を置いた。
After that we declare a new variable/array, here it is called john.
その後、我々は新しい変数/配列を宣言する、ここでは、それはJohnと呼ばれている。
We declare it as our new type, userType.
我々は、それを我々の新しいタイプ(userType)と宣言する。
userType is used like any other type with a variable.
userTypeが、変数で他のどのタイプのようにも使われる。

Now the advantage of using this method is that we can have as many variables as we like with this structure, without having to define another type.
現在、もう一つのタイプを定めなければならないことなく、この方法を使用することの長所は、我々が我々がこの構造で好きであるのと同じくらい多くの変数を持つことができるということである。
We can create more people…
我々は、より多くの人々をつくることができる

john as userType
sam as userType
timmy as userType
claire as userType
male as Boolean = 0
female as Boolean = 1
john.name = “John Smith”
john.gender = male
john.age = 23
john.telphone = 01764 203994
john.height = 1.7
sam.name = “Sam Black”
sam.gender = female

And so on… Note how I used variables to store the male and female values.
そして、そう、 私がどのように男性で女性の値を保存するために変数を使ったかについて気づく。
This is handy when you don’t want to remember that 0 is male and 1 is female.
あなたが0が男性である、そして、1が女性であるのを思い出したくないとき、これは便利である。
Words are more useful than numbers.
語は、数より役に立つ。
An even better form of this would be an array of type.
これのさらにより良い形は、Typeの配列である。
Simply write this line instead of the variable declaring…
単に可変的なdeclaring…の代わりにこの行を書きなさい

dim users(4) as userType

That way all the data is compacted into one array, rather than 4 variables.
そのように、全てのデータは、(4つの変数よりむしろ)1つの配列に圧縮される。
We would access the array like so…
我々は、そのような配列にアクセスする

users(1).name = “F. McSqueeb”
users(4).age = 107

Now, if we say, had two identical twins (who were exactly the same other than their name), we could write out all their information twice, or we could just do this…
現在、我々が言うならば、2人一卵性双生児(その人は、正確にそれの名前以外の同じことであった)はそうした、我々は二度または我々がちょうどこれをすることができたという全てのそれの情報を書き尽くすことができた

users(1).name = “Bill”
users(1).gender = male
users(1).age = 16
users(1).telephone = 03864 193468
users(1).height = 1.54
users(2) = users(1)
users(2).name = “Ben”

So long as the two variables are of the same type, you can simply write a = b and all the values will be transferred across.
2つの変数が同じタイプの限り、あなたは単に A=bを書くことができる、そして、全ての値は横切って移される。
This will save time copying all the values out one at a time in some situations.
これは、若干の状況で一つずつ全ての値を全部コピーしている時間を節約する。

Going on to the next thing to do with user defined types, types within types.
ユーザーと次の行いに移ることは、タイプ(タイプの範囲内のタイプ)を定めた。
The sub-variables within types can have sub-variables of their own!
タイプの範囲内の下位変数は、それ自身の下位変数を持つことができる!
So you could have something like…
あなたが幾分like…を持つことができたように、

house.livingRoom.door
house.livingRoom.window
house.bathroom.window

Here is how to set it up.
それを準備する方法は、ここにある。
First of all you need to define the room type, with window, door and other things in…
まず第一に、ウインドウ、ドアと他のもので、あなたは部屋タイプを定める必要がある

type roomType
  door as integer
  window as string
  floor as byte
  walls as dword
endtype

Then we need to set up the house type, with all the rooms in, and a few other variables that won’t branch off any further…
それから、我々は、中で全ての部屋で、住宅タイプと少しのfurther…からも分岐しない2、3の他の変数を準備する必要がある

type houseType
  houseNumber as word
  numRooms as byte
  livingRoom as roomType
  bathroom as roomType
  diningRoom as roomType
endtype

We simply declare the variables in the type as the room type, then we declare a variable as a roomType and we can access them as above.
我々は単に部屋としてのタイプの変数がタイプすると宣言する、そして、我々は変数をroomTypeと宣言する、そして、我々は上記としてそれらにアクセスすることができる。
You can do as many sub-variable steps as you like.
あなたは、好きなように多くの下位変数なステップとしてすることができる。

Also, as with the whole variables we can transfer information between the sub-variables by doing a.b = c.d…
また、全部の変数と同様に、我々は a.b=c.d にすることによって、下位変数の間で情報を移すことができる

house.livingRoom.door = 1087
house.diningRoom = house.livingRoom
print house.diningRoom.door
wait key

Run that and you will find that the values have been transferred.
それを走らせなさい、そして、あなたは値が移されたとわかる。

Well, that’s it for user defined types…
さて、ユーザー定義済みtypesはこれでおしまい

Summary of Commands

命令の概要

· TYPE typeName - Use this to start defining a type.
TYPE typeName ― 型(タイプ)を定義するためにこれを使う。
The typeName will be the name it will be called by.
typeNameは、それが呼ばれる名前である。

· ENDTYPE - Use this to close a TYPE statement.
ENDTYPE - 型宣言文を閉じるために、これを使いなさい。

End of Section Tasks

セクション終わりの作業

l Create a demo where you can make circles bounce around the screen.
あなたが円をスクリーンをはね回らせることができるデモをつくりなさい。
You should be able to set their colour, x and y speed, size and if you can figure it out, gravity strength.
あなたは、それの色(xとy速度)にサイズを課して、可能ならばそれ(重力強さ)を見つけ出すことができるはずである。
You should also be able to add them in real time (while running the demo) by pressing a button.
あなたは、ボタンを押すことによってリアルタイム(デモを走らせている間)にそれらを加えることができるはずでも。
Use U.D.T.s!
U.D.T.sを使いなさい!