mirJFP
(mir)
July 29, 2024, 6:35pm
#1
I was scripting rarity system. And then I noticed that for i,v in pairs do
loops in a chaotic order. And this ruins the whole probability up
However using ipairs isn’t the solution either. Because ipairs can’t loop through a dictionary. Same thing applies to for i,v in table(dictionary im my case)
This is the proper order
And ths is the order it goes through
dictionaries are an unordered data structure, the key value pairs are not stored in the order you set them
1 Like
notsad2
(nots7d)
July 29, 2024, 6:39pm
#3
ipairs can loop through a dictionary no?
you just print key and then the value after it
notsad2
(nots7d)
July 29, 2024, 6:40pm
#4
ohhh nvm that’s pairs my bad charrr
mirJFP
(mir)
July 29, 2024, 6:40pm
#5
It can’t, i added a print check and it doesnt
notsad2
(nots7d)
July 29, 2024, 6:42pm
#6
hmmm
i’m not sure what you’re trying to use that dictionary for
but perhaps wherever you call it, you could index it with whatever you need so it prints out the correct key and value?
i can’t really get a different idea rn
To get them in order you could try sorting them like this
local Rarities = {
[1] = {
["Content"] = "Fire",
["Rarity"] = 1,
},
[2] = {
["Content"] = "Water",
["Rarity"] = 24,
},
[3] = {
["Content"] = "Earth",
["Rarity"] = 25,
},
[4] = {
["Content"] = "Air",
["Rarity"] = 25,
},
}
for i,v in Rarities do
print(v["Content"] .. " " .. tostring(v["Rarity"]))
end
2 Likes
mirJFP
(mir)
July 29, 2024, 6:51pm
#8
tysmmmm it worked, lemme say some stuff so the post has enough chars
system
(system)
Closed
August 12, 2024, 6:51pm
#9
This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.