View Single Post
06-13-22, 01:42 AM   #7
nonexistentx_x
A Murloc Raider
 
nonexistentx_x's Avatar
Join Date: Mar 2019
Posts: 8
Originally Posted by SDPhantom View Post
Assuming your :get() and :set() functions are working correctly, this is a simpler method.
Lua Code:
  1. ["onclick"]=function(self)
  2.     local newvalue=self.options[Wrap((tIndexOf(self.options,self:get()) or 0))+1,#self.options)];
  3.     self.valueText:SetText(newvalue);
  4.     self:set(newvalue);
  5. end

Note: Both tIndexOf() and Wrap() are Blizzard-defined functions located in SharedXML\TableUtil.lua and SharedXML\MathUtil.lua respectively.
more simple for me:
Lua Code:
  1. function own:getnext(tbl, item)
  2.     local found
  3.     for i = 1, #tbl do
  4.         if found then return tbl[i] end
  5.         found = tbl[i] == item
  6.     end
  7. end
  Reply With Quote