Ok here is the issue I have tried to create a sub table for EnemyData[i].x but I get an error
Runtime error: …g\corona-mobile\beta - projects\test-tables\main.lua:51: attempt to index field ‘?’ (a nil value)
main.lua:51: in function ‘EnemyData’
local EnemyData = {Monster, Orc, Bird};
-------------------------------------------------
--Loop Thru and create sub-tables for EnemyData
-------------------------------------------------
for i = 1, #EnemyData do
EnemyData[i] = {};
EnemyData[i].x = {}; --Table for Random Start Positions
EnemyData[i].y = {}; --Table for Random Start Positions
end
function LoadEnemyData(Enemy, xx, yy)
EnemyData[Enemy].x = xx; ---- \<\< This is where I get the error
EnemyData[Enemy].y = yy;
--------------Load other data--------------
end
LoadInstrumentData("Monster", {150,280,420,550,690}, {205,275,340,415,490,560} )
LoadInstrumentData("Orc", {150,280,420,550,690}, {205,275,340,415,490,560} )
LoadInstrumentData("Bird", {150,280,420,550,690}, {205,275,340,415,490,560} )
I have also tried to do a split and return a table like this.
[code]
function split(pString, pPattern)
local Table = {} – NOTE: use {n = 0} in Lua-5.0
local fpat = “(.-)” … pPattern
local last_end = 1
local s, e, cap = pString:find(fpat, 1)
while s do
if s ~= 1 or cap ~= “” then
table.insert(Table,cap)
end
last_end = e+1
s, e, cap = pString:find(fpat, last_end)
end
if last_end <= #pString then
cap = pString:sub(last_end)
table.insert(Table, cap)
end
return Table
end
function LoadEnemyData(Enemy, xx, yy)
EnemyData[Enemy].x = split(xx, “,”); ---- << This is where I get the error
EnemyData[Enemy].y = split(yy, “,”);
--------------Load other data--------------
end
LoadInstrumentData(“Bird”, “150,280,420,550,690”, “205,275,340,415,490,560” )
[/code] [import]uid: 11860 topic_id: 28141 reply_id: 328141[/import]