The point is, with a for loop, the computer knows the number of iterations, so it can optimize it in some ways.
Anyway, for a more complete example: (I hope I'll get it right, no promises though)
I don't know what your Execute function does, I suppose it's doing something with block in the world using World:GetBlock(); that is gonna be really slow. You really really want to use the BlockArea version of this.
Anyway, for a more complete example: (I hope I'll get it right, no promises though)
Code:
local PlayerX = a_Player:GetPosX();
local PlayerY = a_Player:GetPosY();
local PlayerZ = a_Player:GetPosZ();
local Area = cBlockArea();
if (not(Area:Read(a_Player:GetWorld(), PlayerX - 8, PlayerX + 8, PlayerY - 8, PlayerY + 8, PlayerZ - 8, PlayerZ + 8, cBlockArea.baTypes + cBlockArea.baMetas))) then
-- Cannot read the area around player, bail out
return;
end
local x, y, z;
for y = -8, 8 do
for z = -8, 8 do
for x = -8, 8 do
local BlockType, BlockMeta;
BlockType, BlockMeta = Area:GetRelBlockTypeMeta(x, y, z, BlockType, BlockMeta);
-- stupid ToLua makes us write the last two arguments, they are otherwise useless and unused
-- Do something with the block
end -- for x
end -- for z
end -- for y
I don't know what your Execute function does, I suppose it's doing something with block in the world using World:GetBlock(); that is gonna be really slow. You really really want to use the BlockArea version of this.