Cache trophies #1

Open
opened 2015-02-06 02:56:38 +00:00 by josefnpat · 1 comment
josefnpat commented 2015-02-06 02:56:38 +00:00 (Migrated from github.com)

So for the demo I attached on the forum thread, it'd be great if when I asked for my trophy list, it would cache, and GJ.awardTropy() would update the cache on success, that way I don't need to re-ask the server if the trophy list via GJ.fetchAllTrophies()

I'm wiling to offer a pull request if you like.

Here's my implementiation:

GJ = require "gamejolt"
function love.load()
  GJ.init(48003, "01c30651babd8798ee2e972dae7ffc14")
  GJ.authUser("josefnpat",170094)
  GJ.openSession()
  trophies = GJ.fetchAllTrophies()
end

time = 0

function love.update(dt)
  time = time + dt
  if time > 10 and not time_awarded then
    GJ.giveTrophy(16524)
    trophies = GJ.fetchAllTrophies()
    time_awarded = true
  end
end

log = ""

function love.draw()

  love.graphics.printf(love.timer.getFPS(),0,0,love.graphics.getWidth(),"right")

  local s = ""
  for i,v in pairs(trophies) do
    s = s .. i .. ":\n"
    for j,w in pairs(v) do
      s = s .. j .. " - " .. w .. "\n"
    end
    s = s .. "\n"
  end

  love.graphics.print(s.."\n\n"..log)

end

function love.mousepressed()
  GJ.giveTrophy(16523)
  trophies = GJ.fetchAllTrophies()
end

function love.keypressed(key)
  if key == "b" then
    GJ.giveTrophy(16525)
    trophies = GJ.fetchAllTrophies()
  end
end

function love.quit()
  GJ.closeSession()
end
So for the demo I attached on the forum thread, it'd be great if when I asked for my trophy list, it would cache, and `GJ.awardTropy()` would update the cache on success, that way I don't need to re-ask the server if the trophy list via `GJ.fetchAllTrophies()` I'm wiling to offer a pull request if you like. Here's my implementiation: ``` GJ = require "gamejolt" function love.load() GJ.init(48003, "01c30651babd8798ee2e972dae7ffc14") GJ.authUser("josefnpat",170094) GJ.openSession() trophies = GJ.fetchAllTrophies() end time = 0 function love.update(dt) time = time + dt if time > 10 and not time_awarded then GJ.giveTrophy(16524) trophies = GJ.fetchAllTrophies() time_awarded = true end end log = "" function love.draw() love.graphics.printf(love.timer.getFPS(),0,0,love.graphics.getWidth(),"right") local s = "" for i,v in pairs(trophies) do s = s .. i .. ":\n" for j,w in pairs(v) do s = s .. j .. " - " .. w .. "\n" end s = s .. "\n" end love.graphics.print(s.."\n\n"..log) end function love.mousepressed() GJ.giveTrophy(16523) trophies = GJ.fetchAllTrophies() end function love.keypressed(key) if key == "b" then GJ.giveTrophy(16525) trophies = GJ.fetchAllTrophies() end end function love.quit() GJ.closeSession() end ```
mbrovko commented 2015-02-06 09:40:38 +00:00 (Migrated from github.com)

Sounds like a nice idea. I'll take a look!

Sounds like a nice idea. I'll take a look!
This repo is archived. You cannot comment on issues.
No Milestone
No project
No Assignees
1 Participants
Due Date
The due date is invalid or out of range. Please use the format 'yyyy-mm-dd'.

No due date set.

Dependencies

No dependencies set.

Reference: library-mirrors/gamejoltlua#1
No description provided.