Posted 24 November 2012 - 02:34 AM
function getindex(index, items)
i = index
while i > items do i = i - items end
while i < 1 do i = i + items end
return i
end
function SelectionMenu(title, ...)
DefaultMenu(title)
index = 1
items = {...}
len = table.getn(items)
CenterString("> "..items[getindex(index, len)].." <", 5)
for i=1,12,1 do
if items[getindex(index + i, len)] == nil then
CenterString(getindex(index + i, len), 5 + i) -- debug
else
CenterString(items[getindex(index + i, len)], 5 + i)
end
end
end
I've got this code, and the idea is that it should not be possible to give out of range indexes of the array items[] by using getindex, but it seems to be giving weird outputs between 5-10, 11 or above seems to work better,
what it does now at 6-10 is
6 = 6
7 = 1
8 = 8
9 = 1
10 = 10
11 and 12 seem to be giving the correct options again.
I'm executing SelectionMenu with this command:
menu.SelectionMenu("Main menu", "Start game", "options", "settings", "tutorial", "Multiplayer")
Thanks for helping/reading