Thatâ€™s a neat idea! I might use this in my own game!

Letâ€™s make a 2D array called logicChain. This will hold our logic and respective results.

A conditional statement has two parts to it: a condition and a result. Letâ€™s store those like this in the array: { {condition1, result1}, {condition2, result2}, â€¦ }

Now, we need a loop to go through the table and evaluate each condition. If we want to have an â€śelseâ€ť statement at the end, we can just put it as the last entry in the table and have the condition just set to true, so it will execute if nothing else in the table does.

We also need to provide a noMatchResult in case none of our conditions match. nil seems intuitive to me in most cases, but sometimes you may need to use something else.

I believe the condition will evaluate as soon as you declare the logic table, so you need to re-create the table each time you call it.

```
function evaluateLogicTable(logicTable, noMatchResult)
local logicTableEvalIndex = 1
while (logicTableEvalIndex <= #logicTable) do
if logicTable[logicTableEvalIndex][1] then
return logicTable[logicTableEvalIndex][2]
end
logicTableEvalIndex = logicTableEvalIndex + 1
end
return noMatchResult
end
local x = 3
local logicTable = { {(x > 4), â€śX is greater than 4â€ť}, {(x > 2), â€śX is greater than 2â€ť}, {true, â€śAn else condition if we want oneâ€ť} }
print(evaluateLogicTable(logicTable, nil))
-- Will output â€śX is greater than 2â€ť
local x = 5
print(evaluateLogicTable(logicTable, nil))
-- Will output â€śX is greater than 2â€ť, since the original logicTable does NOT get re-evaluated until it gets reassigned
logicTable ={ {(x > 4), â€śX is greater than 4â€ť}, {(x > 2), â€śX is greater than 2â€ť}, {true, â€śAn else condition if we want oneâ€ť} }
print(evaluateLogicTable(logicTable, nil))
-- Will now output â€śX is greater than 4â€ť as we expect since the conditions have been re-evaluated
```

â€”â€”â€”â€”â€”â€”â€”â€”â€”â€”â€”

To make life easier for you, just use a function that resets/re-evaluates your logic table every time you need it:

```
-- Updating by function call (RECOMMENDED)
function getMyLogicTable()
return { {(x > 4), â€śX is greater than 4â€ť}, {(x > 2), â€śX is greater than 2â€ť}, {true, â€śAn else condition if we want oneâ€ť} }
end
logicTable = getMyLogicTable()
-- Updating by global variable
logicTable = nil
function getMyLogicTable()
logicTable = { {(x > 4), â€śX is greater than 4â€ť}, {(x > 2), â€śX is greater than 2â€ť}, {true, â€śAn else condition if we want oneâ€ť} }
end
getMyLogicTable()
```