スクリプト/配列を一気に設定する関数(履歴ID:184)

最終投稿者:Material 7186 1 mini ikosami 更新:2015/09/30 16:20:03
普通に配列をたくさん設定する場合、
a = createArray()
a[0] = createArray()
a[0][0] = 1; a[0][1] = 2; a[0][2] = 3;
a[0][3] = 4; a[0][4] = 5; a[0][5] = 6;
a[0][6] = 7; a[0][7] = 8; a[0][8] = 9; a[0][9] = 10;
a[1] = createArray()
a[1][0] = 1; a[1][1] = 2; a[1][2] = 3;
a[1][3] = 4; a[1][4] = 5; a[1][5] = 6;
a[1][6] = 7; a[1][7] = 8; a[1][8] = 9; a[1][9] = 10;
a[2] = createArray()
a[2][0] = 1; a[2][1] = 2; a[2][2] = 3;
a[2][3] = 4; a[2][4] = 5; a[2][5] = 6;
a[2][6] = 7; a[2][7] = 8; a[2][8] = 9; a[2][9] = 10;

などと、長々と書く必要が出てきますが、
この関数を使えば簡単に書くことができます。

def Array(a)
  a = splitString(a, ",")
  i = 0
  while i < getArrayLength(a)
    if (toNumber(a[i])*1 == toNumber(a[i]))
      a[i] = toNumber(a[i])
    end
    i = i + 1
  end
return a
end



↓使用例
a = createArray()
a[0] = Array("リンゴ,250")
a[1] = Array("メロン,1000")
a[2] = Array("バナナ,100")

r = rand(3)
speak(a[r][0]+"は"+a[r][1]+"円です")