|
Post by Mercobots on Nov 27, 2018 2:14:26 GMT
but if it was a 0 at 6th of table E the result would be something like this
(0,0,0,8,8,8,1,1,1,1,1,1,1,0,0,8,8,8,0,0,0,0,0,0,0,0,8,8,8,8,0,8,8,8,8,8) ?
|
|
kideas
Junior Member
Posts: 69
|
Post by kideas on Nov 27, 2018 2:19:36 GMT
function table_merge(t1, t2) for _, v in ipairs(t2) do table.insert(t1, v) end end
function all1(tbl) for i, v in ipairs(tbl) do if tonumber(v) ~= 1 then return false end end return true end local myList = { {Sa11,Sa12,Sa13,Sa14,Sa15,Sa16}, {Sa21,Sa22,Sa23,Sa24,Sa25,Sa26}, {Sa31,Sa32,Sa33,Sa34,Sa35,Sa36}, {Sa41,Sa42,Sa43,Sa44,Sa45,Sa46}, {Sa51,Sa52,Sa53,Sa54,Sa55,Sa56}, {Sa61,Sa62,Sa63,Sa64,Sa65,Sa66}, {Sa71,Sa72,Sa73,Sa74,Sa75,Sa76}, {Sa81,Sa82,Sa83,Sa84,Sa85,Sa86}, {Sa91,Sa92,Sa93,Sa94,Sa95,Sa96}, {SaX1,SaX2,SaX3,SaX4,SaX5,SaX6}, {Sa1X1,Sa1X2,Sa1X3,Sa1X4,Sa1X5,Sa1X6}, {Sa2X1,Sa2X2,Sa2X3,Sa2X4,Sa2X5,Sa2X6}, {Sa3X1,Sa3X2,Sa3X3,Sa3X4,Sa3X5,Sa3X6}, {Sa4X1,Sa4X2,Sa4X3,Sa4X4,Sa4X5,Sa4X6}, {Sa5X1,Sa5X2,Sa5X3,Sa5X4,Sa5X5,Sa5X6}, {Sa6X1,Sa6X2,Sa6X3,Sa6X4,Sa6X5,Sa6X6}, {Sa7X1,Sa7X2,Sa7X3,Sa7X4,Sa7X5,Sa7X6}, {Sa8X1,Sa8X2,Sa8X3,Sa8X4,Sa8X5,Sa8X6}, {Sa9X1,Sa9X2,Sa9X3,Sa9X4,Sa9X5,Sa9X6}, {SaXX1,SaXX2,SaXX3,SaXX4,SaXX5,SaXX6}, {Sa1XX1,Sa1XX2,Sa1XX3,Sa1XX4,Sa1XX5,Sa1XX6}, {Sa2XX1,Sa2XX2,Sa2XX3,Sa2XX4,Sa2XX5,Sa2XX6}, }
local _result, _temp = {}, {} local _key_master
for k, tbl in pairs(myList) do if not _key_master then if all1(tbl) then _key_master = k else table_merge(_result, tbl) end else if tonumber(tbl[#tbl]) == 1 then table.insert(myList[_key_master], "1") table.remove(tbl, #tbl) end table_merge(_temp, tbl) end end table_merge(_result, myList[_key_master]) table_merge(_result, _temp)
--
print(table.concat(_result,",")) please I'm still getting the same error...help
|
|
kideas
Junior Member
Posts: 69
|
Post by kideas on Nov 27, 2018 2:22:13 GMT
but if it was a 0 at 6th of table E the result would be something like this (0,0,0,8,8,8,1,1,1,1,1,1,1,0,0,8,8,8,0,0,0,0,0,0,0,0,8,8,8,8,0,8,8,8,8,8) ? exactly!
|
|
|
Post by Mercobots on Nov 27, 2018 2:30:40 GMT
ok try run this and send me the result
for t_i,t in ipairs(myList) do
if typeOf(t) ~= 'table'then
print(t_i,'is not a table')
scriptExit()
end
for i,v in ipairs(t) do
print(v,typeOf(v))
end
end
|
|
kideas
Junior Member
Posts: 69
|
Post by kideas on Nov 27, 2018 2:43:28 GMT
ok try run this and send me the result
for t_i,t in ipairs(myList) do
if typeOf(t) ~= 'table'then
print(t_i,'is not a table')
scriptExit()
end
for i,v in ipairs(t) do
print(v,typeOf(v))
end
end
1 string 1 string 8 string 8 string 8 string 8 string 0 string 0 string 8 string 8 string 8 string 8 string
|
|
kideas
Junior Member
Posts: 69
|
Post by kideas on Nov 27, 2018 2:44:20 GMT
it printed in such manner. the value and type
|
|
|
Post by Mercobots on Nov 27, 2018 2:45:38 GMT
so the error is because you have empty vars
|
|
kideas
Junior Member
Posts: 69
|
Post by kideas on Nov 27, 2018 2:51:01 GMT
so the error is because you have empty vars they are not supposed to be empty. each row of will have either "1" or "0" or "8" as the value
|
|
kideas
Junior Member
Posts: 69
|
Post by kideas on Nov 27, 2018 2:55:26 GMT
as I said my code works and print out the values. but now I need to modify it so it can meet the current requirement in comparing to see if all rows have 1,1,1,1,1 and if so check the 6th row of the next column to see 1 is present; and if present insert it and check again until false then come back to continue excluding the already recorded 6th values
|
|
|
Post by Mercobots on Nov 27, 2018 3:03:14 GMT
tomorrow i will see what is happening,for now is done for me
|
|
kideas
Junior Member
Posts: 69
|
Post by kideas on Nov 27, 2018 3:08:46 GMT
tomorrow i will see what is happening,for now is done for me Thanks for support. really appreciate
|
|
|
Post by Mercobots on Nov 27, 2018 3:14:40 GMT
tomorrow i will see what is happening,for now is done for me Thanks for support. really appreciate btw try this one function table_merge(t1, t2) for _, v in ipairs(t2) do table.insert(t1, v) end end
function alltheSame(tbl, val) for _, v in ipairs(tbl) do if tonumber(v) ~= tonumber(val) then return false end end return true end
function getTalble() end
function all1(tbl) for i, v in ipairs(tbl) do if tonumber(v) ~= 1 then return false end end return true end
local myList = { { 0, 0, 0, 8, 8, 8 }, { 1, 1, 1, 1, 1, 0 }, { 0, 0, 8, 8, 8, 0 }, { 0, 0, 0, 0, 0, 0 }, { 0, 8, 8, 8, 8, 8 }, { 0, 8, 8, 8, 8, 8 }, }
local _result, _temp = {}, {} local _key_master
for k, tbl in pairs(myList) do if not _key_master then if all1(tbl) then _key_master = k else table_merge(_result, tbl) end else if tonumber(tbl[#tbl]) == 1 then table.insert(myList[_key_master], "1") table.remove(tbl, #tbl) end table_merge(_temp, tbl) end end if _key_master then table_merge(_result, myList[_key_master]) end table_merge(_result, _temp)
--
print(table.concat(_result, ","))
|
|
kideas
Junior Member
Posts: 69
|
Post by kideas on Nov 27, 2018 3:49:24 GMT
Thanks for support. really appreciate btw try this one function table_merge(t1, t2) for _, v in ipairs(t2) do table.insert(t1, v) end end
function alltheSame(tbl, val) for _, v in ipairs(tbl) do if tonumber(v) ~= tonumber(val) then return false end end return true end
function getTalble() end
function all1(tbl) for i, v in ipairs(tbl) do if tonumber(v) ~= 1 then return false end end return true end
local myList = { { 0, 0, 0, 8, 8, 8 }, { 1, 1, 1, 1, 1, 0 }, { 0, 0, 8, 8, 8, 0 }, { 0, 0, 0, 0, 0, 0 }, { 0, 8, 8, 8, 8, 8 }, { 0, 8, 8, 8, 8, 8 }, }
local _result, _temp = {}, {} local _key_master
for k, tbl in pairs(myList) do if not _key_master then if all1(tbl) then _key_master = k else table_merge(_result, tbl) end else if tonumber(tbl[#tbl]) == 1 then table.insert(myList[_key_master], "1") table.remove(tbl, #tbl) end table_merge(_temp, tbl) end end if _key_master then table_merge(_result, myList[_key_master]) end table_merge(_result, _temp)
--
print(table.concat(_result, ","))
i got this result: 0,0,0,8,8,8,1,1,1,1,1,0,0,0,8,8,8,0,0,0,0,0,0,0,0,8,8,8,8,8,0,8,8,8,8,8 almost as expected
|
|
kideas
Junior Member
Posts: 69
|
Post by kideas on Nov 27, 2018 3:57:09 GMT
the results is without commas
|
|
|
Post by Mercobots on Nov 27, 2018 9:51:11 GMT
OK but try the code above using your table and check if you still getting the same erro
|
|