For some strange reason, the following simple usage of next() in finding the next value is causing the error in the title.
local validObjects = {}
local validNames = {}
for name, styleObject in pairs(PlayerCombatStyles) do
if styleObject.WeaponClass == CurrentCombatStyle.WeaponClass then
validObjects[name] = styleObject
table.insert(validNames, name)
end
end
--[[ This does not seem to affect it??
table.sort(validNames, function(a,b)
return a < b
end)
]]
local nextStyleName, combatStyleValue = next(validNames, CurrentCombatStyle.Name)
Right now I use table.sort() to sort the indices of the dictionary (which are strings contained in the validNames array) so that they are alphabetical.
CurrentCombatStyle.Name’s value is a string (this code won’t run if this is nil), and the validNames array should contain the string indices of the dictionary (which are names of combat styles).
Oh yeah I see. What are you trying to do with that line? next is generally reserved for working with dictionaries and you pass it the key, not the value.
I can see here that validNames is an array, so CurrentCombatStyle.Name (which you say is a string) will indeed cause an error with next because next expects in this case a valid integer key for the validNames array.