You probably also only want to check for changes happening to the score, and only sending the message when such a change has brought the score over one of these levels. If the score is only incremented and this doesn’t happen for too many things, something like this could work:
function init(self)
self.score_levels = {250, 500}
end
local notify(self, score)
-- for each listener:
msg.post(listener, "score_reached", {score = score})
end
local function incr_score(self, value)
self.score = self.score + value
local next_level = self.score_levels[1]
while (next_level and next_level <= self.score) do
notify(self, next_level)
table.remove(self.score_levels, 1)
next_level = self.score_levels[1]
end
end