URL: http://atnd.org/events/34622
おはよう、こんにちは。こんばんは。
結局今日も書くことになりました。
・ちなみに技評にのったよ
http://gihyo.jp/news/info/2012/12/0101
・ここにはまだない(・∀・)
http://matome.naver.jp/odai/2135217818800380701
最近Pythonやってなくてよく忘れるが、
BooもListとArrayを明確に分けてます。
・Array
これがArrayです。
()カッコにstring型入れてます。
my_array as (string) = (string, "one", "two", "three") for i in my_array: Debug.Log(i)
→ 結果
one
two
three
公式ドキュメントではアンダースコア区切りはしてませんでした。
0番目に型を書けばその型になるようです。
my_array as (string) = ("one", "two", "three") for i in my_array: Debug.Log(i)
→ 結果(同じ)
one
two
three
・List
今回主役のListです・
[]で書きます。UnityScriptの配列的な書き方なので混合しそう。
Arrayと違うのは、どんなかたも入れれること。
my_list as List = ["foo", "bar", "baz", 0, 1, 2] Debug.Log(my_list) for item in my_list: Debug.Log(item)
→ 結果
foo
bar
baz
0
1
2
・if文でこんな書き方ができます。my_list内に"foo"があるかを判別できます
my_list as List = ["foo", "bar", "baz", 0, 1, 2] if my_list.Find({item | return item == "foo"}): Debug.Log("found foo");
intの判別もできる
my_list as List = [0, 1, 2] if my_list.Find({ i as int | i > 5 }): Debug.Log("found more than 5");
"as int"を書かないとobjectと比較演算子使ってるとこのエラーが出るので注意。
InvalidCastException: Cannot cast from source type to destination type.
では次の方よろしくです。