Code: Select all
function audienceStateCheck()
audienceDiscontent = 0
audienceNeutral = 0
audienceContent = 0
for i = 1,#audience do
if audience[i].mood == "content" then
audienceContent = audienceContent + 1
elseif audience[i].mood == "neutral" then
audienceNeutral = audienceNeutral + 1
elseif audience[i].mood == "discontent" then
audienceDiscontent = audienceDiscontent + 1
end
end
end
personGuyOne = { name = "Guy One", age = 52, gender = male, likes = {"glad", "happy"}, dislikes = {"sunday"}, mood = "discontent" }
personGalTwo = { name = "Gal Two", age = 42, gender = female, likes = {"dancing", "map", "history"}, dislikes = {"vibrant"}, mood = "content" }
audience = {personGuyOne, personGalTwo}
And this loop works! Yay for me. But it feels clunky and I'm not sure whether it'll give me bugs later on down the road. It seems like there should be a simpler/better way to say, "Add up all the instances of thing X within table Y". Something with the string. library?