Posted 30 July 2014 - 04:06 AM
What I am trying to do.
I am making a dynamically learning bee breeding program using CC and openP and having some issues trying to get one of my nested tables to work correctly. I am wanting my table to look like something below
{result= {1={species1,species2},2={species1,species2}}}
the reason for the 1= and 2= is to have all the different combos for the same bee listed such as common which has many. (and not have multiple "results" as common as that will break what I am trying to do as well)
currently my table has came out in many different wrong ways but its always either looking like the below
{result={1={species1,species2,species3,species4,…}}}
or
{result={species1,species2}} <—- missing all the other combos and just picks two to stay.
in spoiler below is current code I am working with.
for k,v in ipairs(testing) do
for k1,v1 in pairs(testing[k]) do
if k1 == "result" then
result = v1
elseif k1 == "allele1" then
species1 = v1
elseif k1 == "allele2" then
species2 = v1
end
end
if not breedingTable[result] then
breedingTable[result] = {}
end
table.insert(breedingTable[result])
table.insert(breedingTable[result],species1)
table.insert(breedingTable[result],species2)
– breedingTable[result][species1] = {}
– breedingTable[result][species2] = {}
endlink to pastebin of code, http://pastebin.com/tUN12yxj
any advice or better reading material (read quite a bit of the LUA reference manual) would be a great help to me.
p.s. yes I know someone already created a program to do this but I dont want to use it for two reasons.
1. its a static list and will not adapt as things change.
2. most importantly, I think using the whole of someone else's code takes the fun and challenge out of it (though I do read a lot of them to try and learn things)
I am making a dynamically learning bee breeding program using CC and openP and having some issues trying to get one of my nested tables to work correctly. I am wanting my table to look like something below
{result= {1={species1,species2},2={species1,species2}}}
the reason for the 1= and 2= is to have all the different combos for the same bee listed such as common which has many. (and not have multiple "results" as common as that will break what I am trying to do as well)
currently my table has came out in many different wrong ways but its always either looking like the below
{result={1={species1,species2,species3,species4,…}}}
or
{result={species1,species2}} <—- missing all the other combos and just picks two to stay.
in spoiler below is current code I am working with.
Spoiler
testing = apiary.getBeeBreedingData()for k,v in ipairs(testing) do
for k1,v1 in pairs(testing[k]) do
if k1 == "result" then
result = v1
elseif k1 == "allele1" then
species1 = v1
elseif k1 == "allele2" then
species2 = v1
end
end
if not breedingTable[result] then
breedingTable[result] = {}
end
table.insert(breedingTable[result])
table.insert(breedingTable[result],species1)
table.insert(breedingTable[result],species2)
– breedingTable[result][species1] = {}
– breedingTable[result][species2] = {}
end
any advice or better reading material (read quite a bit of the LUA reference manual) would be a great help to me.
p.s. yes I know someone already created a program to do this but I dont want to use it for two reasons.
1. its a static list and will not adapt as things change.
2. most importantly, I think using the whole of someone else's code takes the fun and challenge out of it (though I do read a lot of them to try and learn things)