--corresponding numbers
1:1
2:2
3:3
4:4
5:1
6:2
7:3
8:4
9:1
10:2
11:3
12:4
--current method:
for i=1,3 do
local index = ((safe+(i-1))%4)
if index==0 then index=4 end
end
wondering if there’s a simpler way to do this without a for loop
--corresponding numbers
1:1
2:2
3:3
4:4
5:1
6:2
7:3
8:4
9:1
10:2
11:3
12:4
--current method:
for i=1,3 do
local index = ((safe+(i-1))%4)
if index==0 then index=4 end
end
wondering if there’s a simpler way to do this without a for loop
So, for any given number ‘n’ this should give a corresponding value between 1 and 4 according to your pattern.
local i = ((n - 1) %4) + 1
Edit: I wasn’t sure on the behaviour with negative numbers but after testing it this should work for anything.
you had the right idea
local Safe = 9
local Index = (Safe - 1) % 4 + 1
print(Index) --> 1