HiveBrain v1.2.0
Get Started
← Back to all entries
patternMinor

Consolidating array accesses

Submitted by: @import:stackexchange-codereview··
0
Viewed 0 times
arrayconsolidatingaccesses

Problem

Is there a better or easier way of doing this?

if array[1] and array[2] and array[3] and array[4] and array[5] == false then

    --somthing

end


I have a lot of arrays to check and was wondering if there is a way to work with arrays where you can do something like array[1-6] or [1,6] or something. Can't seem to find anything online.

Solution

I'm not sure of the lua syntax but something like

arrayAllFalse=TRUE;
for element in array
  if (element) then 
  arrayAllFalse=FALSE
  end

if (arrayALLFalse) then
    --something
end

Code Snippets

arrayAllFalse=TRUE;
for element in array
  if (element) then 
  arrayAllFalse=FALSE
  end

if (arrayALLFalse) then
    --something
end

Context

StackExchange Code Review Q#8468, answer score: 2

Revisions (0)

No revisions yet.