I'm trying to select the random item from table but in the way that the new element is not equal to the last element so, in this way we are sure that the new item will not be the recently selected item.
But maybe I do not understand something in lua.
local last_element = client:get('daily:last')
local new_element = nil
if(last_element == nil) then
new_element = selectNewQuest()
else
-- Randomizing elements from table until selected the proper one (not used in the last daily quest)
while true do
new_element = selectNewQuest()
print (new_element)
if new_element ~= last_element then
print(new_element ~= last_element)
print("NEW ELEMENT: " .. new_element)
print("LAST ELEMENT: " .. last_element)
print("BREAKED")
break
end
print("Iterating")
end
end
client:set('daily:last', new_element)
function selectNewQuest()
return math.random(#Table)
end
Can someone tell me how it's possible that for example: if 1 ~= 1 is true? It is not work properly for me. Maybe there is some bug or something in my code?
Aucun commentaire:
Enregistrer un commentaire