View Single Post
06-13-22, 05:52 AM   #9
nonexistentx_x
A Murloc Raider
 
nonexistentx_x's Avatar
Join Date: Mar 2019
Posts: 8
Originally Posted by Kanegasi View Post
That's smart, I tend to get a little complicated before I get the code slimmed down.

However, that won't return the first indexed item if you feed it the last one. I adjusted it:

Lua Code:
  1. function own:getnext(tbl, item)
  2.     if tbl[#tbl] == item then
  3.         return tbl[1]
  4.     else
  5.         local found
  6.         for i = 1, #tbl do
  7.             if found then
  8.                 return tbl[i]
  9.             end
  10.             found = tbl[i] == item
  11.         end
  12.     end
  13. end
it returns the first index, just need to write it otherwise:
Lua Code:
  1. local newvalue = self:getnext(self.options, self:get()) or self.options[1];
  Reply With Quote