Easier to type and faster to execute, one lookup penalty vs 3 as in your example. Also, as you add more lines like that you add one penalty per lookup. Again though, easier to type ‘tmp’ than ‘touchImages[i]’ over and over.
So a “lookup” is just related to tables, or is (what you do later) tmp.x = curX considered a “lookup” as well? I assume it has to lookup curX to get the value - the only diff being curX is not a tble.
PPS. Thanks Roam for this little understanding
[lua]
local perRow = 4
for i = 1, 12 do
if( i % perRow == 0 ) then
print(“hey every 4th”)
else
print(“NOT a 4th”)
end
end
[\lua]
OP.
Roam has used touch event whereas it appears you want to use tap.
Roams code creates display objects via a loop - easier than creating individual.
adds the listener within the loop rather than 12 adlistner lines
Then rather than doing obj.x, and obj.y for each individually - does some math based on starting position of the first display obj to position the remaining 11 obj - all within the loop.
As for the function your original post function did something with alpha - but was unclear - so his function looped thru all images making alpha 0.5 and then the one you touched - it’s alpha is put back to 1 to make it stand out.
Easier to type and faster to execute, one lookup penalty vs 3 as in your example. Also, as you add more lines like that you add one penalty per lookup. Again though, easier to type ‘tmp’ than ‘touchImages[i]’ over and over.
So a “lookup” is just related to tables, or is (what you do later) tmp.x = curX considered a “lookup” as well? I assume it has to lookup curX to get the value - the only diff being curX is not a tble.
PPS. Thanks Roam for this little understanding
[lua]
local perRow = 4
for i = 1, 12 do
if( i % perRow == 0 ) then
print(“hey every 4th”)
else
print(“NOT a 4th”)
end
end
[\lua]
OP.
Roam has used touch event whereas it appears you want to use tap.
Roams code creates display objects via a loop - easier than creating individual.
adds the listener within the loop rather than 12 adlistner lines
Then rather than doing obj.x, and obj.y for each individually - does some math based on starting position of the first display obj to position the remaining 11 obj - all within the loop.
As for the function your original post function did something with alpha - but was unclear - so his function looped thru all images making alpha 0.5 and then the one you touched - it’s alpha is put back to 1 to make it stand out.