My for loop isnt running

So i want to create a weighted distribution system in my game but it needs to work a little different to the normal ones. However i am trying to use a for loop to add all the values in a table but its just not working

Anyone know if im doing something wrong? Also the rounding function just rounds the numbers and ive tested it and its working just fine

i also fixed that malformed number, so just ignore that

You need a dictionary not a table What's the difference between a table and a dictionary? - #4 by ReturnedTrue

How do i do that? I changed the commas to semi colons and nothing happened

Are you sure the rounding function is returning a value? Try printing one of the room values and see what it yields.

Yes im sure it does, ive checked many times

Can you print the table and show us what it looks like before entering the for loop?

Do you mean dumping the values or showing you whats in the table. Because the actual table is in the screenshot

My bad, I skimmed your code too fast and missed the ipairs. @h_pup mentioned your solution above where you can either use a dictionary instead of an table or switch the ipairs out for pairs.


for i, v in pairs(room) do --> Substituded ipairs -> pair
    weight += 2
    print(v)
end
1 Like

My god, thank you so much that has fixed everything. I thought that ipairs is for getting numerical values in tables but i guess im wrong

1 Like