Sorry your browser is not supported!

You are using an outdated browser that does not support modern web technologies, in order to use this site please update to a new browser.

Browsers supported include Chrome, FireFox, Safari, Opera, Internet Explorer 10+ or Microsoft Edge.

AppGameKit Classic Chat / How do I create multiple player profiles in json?

Author
Message
basicFanatic
7
Years of Service
User Offline
Joined: 7th Jun 2017
Location:
Posted: 2nd Mar 2020 22:58
It's strange. One of these cases where I almost has the answer. I know I have to make an array, so I can swith the active profile with switching the player integer: profile[player]. But when I somehow try to put this into practice ... my brain just refuse to work with it.

What would be the best approach if I want to save level progress, topscore, etc, for two seperate profiles?

My current code goes like this:


blink0k
Moderator
11
Years of Service
User Offline
Joined: 22nd Feb 2013
Location: the land of oz
Posted: 2nd Mar 2020 23:50 Edited at: 2nd Mar 2020 23:57
Add player to dataThing

Type dataThing
player as string
levels as levelThing[]
someStuff as integer
moreStuff as integer
Endtype

Then search through the aGameData array till the player matches. If not add it.

You could use .insertsorted() and .find() to search for the player

Alternatively you could name the JSON file after the player
nz0
AGK Developer
17
Years of Service
User Offline
Joined: 13th Jun 2007
Location: Cheshire,UK
Posted: 4th Mar 2020 02:45
I would do something like this:

type tProfile
Levels as LevelThing[]
PlayerName$ as String
Score as Integer
LevelProgress as Integer
endtype

Global Players as tProfile[]

Json and arrays are compatible.
Load the json file into the empty array and it will fill automatically.
Sometimes, I will set up the data structure and save it as Json to give me a template to edit.

Login to post a reply

Server time is: 2024-11-22 11:32:42
Your offset time is: 2024-11-22 11:32:42