Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
2

issue with Table.Sort?

Asked by 9 years ago

23:56:55.337 - attempt to yield across metamethod/C-call boundary

table.sort(eloTab, function(x,y) return ratingData:GetAsync(x).Rating > ratingData:GetAsync(y).Rating end)

This seems to occur whenever I grab the Elo ranking of each player. and try to sort it by who's higher up.

1 answer

Log in to vote
3
Answered by
Unclear 1776 Moderation Voter
9 years ago

GetAsync is not an instantaneous method and therefore yields the current thread until a result is fetched.

table.sort requires a callback function as its second argument to specify the sort. Callback functions should never contain code that yields.

What I would suggest you do is iterate through all players and cache their current ELO rating every few seconds (or better yet, once when they join and then again everytime their rating is updated). Store the cache in a table, and then fetch the value in the table because there is no yielding necessary for that.

Edit: If you need to access all possible players... just use GetSortedAsync and iterate over all of the pages rather than using GetAsync... just because the players are not in the game doesn't change the fact that caching is the solution.

0
This would work, however I need to be able to access all players who HAVE a ranking, so even if their not in the game. PuzzleMeThis 15 — 9y
0
You're overthinking this. Read my edit. Unclear 1776 — 9y
Ad

Answer this question