Achievements in game. Small help?

Hi guys

I wanted to create the Achievements in game outside of google play etc.

I’ve never done such a thing so I have two questions:

  1. Logically I’m forced to put the increases on the points or there another way? For Example, The goal is: eliminate 10 balls. So every time I delete a ball I will have to do something like 

    ballsEliminated = ballsEliminated +1

?

  1. For simplicity I often look to create a vector, so the items would have numerical indices and not string. Why should I remember me the number of each objective? If that were the point one should go as well 

    achievements[1] = achievements[1] + 1

 ?

thanks in advance for availability

  1. Yes. Don’t forget to save those values to some permanent storage if you want to keep tracking it.

  2. You can go both ways with this but it would be easier to use string keys as it will be easier for you to follow and probably save you from many logical mistakes.

Thank you bgmadclown

 

  1. I thought of storing a file Json in system.DocumentsDirectory.

2.something like this:

local Achievements = {} Achievements[1] = {} Achievements["ballsEliminated"] = Achievements[1] --2 --3 --etc 

right?

however in this case I should create a first table from the keyboard personally

You can create the JSON file as an asset in your project where you keep all your achievement texts, win conditions etc. and create another file where you keep progress of the player in runtime in the DocumentsDirectory. Don’t forget to process them in tables though. Otherwise, working with files will cost you performance-wise.

OK OK Thank you very much.

With “Do not forget to process them in tables though” you’re referring to insert data into a table lua every time I have them use it? In this case use the form loadsave okay?

I thought in the system.ResourceDirectory:

data

local M = { { title = "title\_1", description = "description\_1", requiredNumber = 10, }, { title = "title\_2", description = "description\_2", requiredNumber = 100, }, } --etc return M

initialization to json in system.DocumentsDirectory:

local data = require("data") local loadSave = require("loadSave") local dataUser = {} for i = 1, #data do dataUser [i] = {} dataUser [i].currentNumber = 0 end loadSave.saveTable (dataUser , "dataUser.json", system.DocumentsDirectory)

You can go well?

Yep, I’m saying that exactly. Do all your work with tables and after you are finished with it, save it into the file. Try not to use any file related stuff while the player is in-game.

  1. Yes. Don’t forget to save those values to some permanent storage if you want to keep tracking it.

  2. You can go both ways with this but it would be easier to use string keys as it will be easier for you to follow and probably save you from many logical mistakes.

Thank you bgmadclown

 

  1. I thought of storing a file Json in system.DocumentsDirectory.

2.something like this:

local Achievements = {} Achievements[1] = {} Achievements["ballsEliminated"] = Achievements[1] --2 --3 --etc 

right?

however in this case I should create a first table from the keyboard personally

You can create the JSON file as an asset in your project where you keep all your achievement texts, win conditions etc. and create another file where you keep progress of the player in runtime in the DocumentsDirectory. Don’t forget to process them in tables though. Otherwise, working with files will cost you performance-wise.

OK OK Thank you very much.

With “Do not forget to process them in tables though” you’re referring to insert data into a table lua every time I have them use it? In this case use the form loadsave okay?

I thought in the system.ResourceDirectory:

data

local M = { { title = "title\_1", description = "description\_1", requiredNumber = 10, }, { title = "title\_2", description = "description\_2", requiredNumber = 100, }, } --etc return M

initialization to json in system.DocumentsDirectory:

local data = require("data") local loadSave = require("loadSave") local dataUser = {} for i = 1, #data do dataUser [i] = {} dataUser [i].currentNumber = 0 end loadSave.saveTable (dataUser , "dataUser.json", system.DocumentsDirectory)

You can go well?

Yep, I’m saying that exactly. Do all your work with tables and after you are finished with it, save it into the file. Try not to use any file related stuff while the player is in-game.