Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Tree: faf1e6074a
Fetching contributors…

Cannot retrieve contributors at this time

68 lines (57 sloc) 1.858 kB

Description

lime is a basic high score framework for saving and reloading global and local scores using the corona sdk (anscamobile.com)

Right now it's fairly rough around the edges and only supports some basic abilities for local scores. Local scores are persisted as json files.

Usage

json = require("json")
lime = require("lime")

-- setup
-- maxScores
--   the number of scores to keep per level
--
-- levelKeyFrom
--   the levelKeyFrom option takes a table of property names
--   that are used to generate and group scores, based off of
--   the optios table that you pass in at score creation
--
--   think of them as a method of creating dymanic score boards
--
--   if levelKeyFrom is empty then scores are added into lime as an array,
--   treating it as a single scoreboard
lime.setup({
  maxScores = 10,
  levelKeyFrom = {"difficulty", "level"}
})

-- add a score
--
-- the only required key is "score", scores are kept sorted by "score"
-- if the keys specified in levelKeyFrom during setup are not passed,
-- scores are added into a global, nameless lobby
lime.add({
  score = player.score,
  level = 50,
  difficulty = "hard"
})

-- load all local scores for a level
--
-- localScores returns an array of tables containing whatever you included when adding the score
--   as well as a 'timestamp' field which was the time that the score was added
local scores = lime.localScores({
  level = 50,
  difficulty = "hard"
})

-- get amount of scores in this level
print(#scores)

-- iterate over scores
for i, s in ipairs(scores) do
  local addedAt = lime.formatTimestamp(s.timestamp)
  print(s.score, addedAt)
end

-- clear all scores for a level,
lime.clear({
  level = 50,
  difficulty = "hard"
})

-- write scores to a file
lime.save()
Jump to Line
Something went wrong with that request. Please try again.