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 / Will this array retain the names if the game is shut down and then re-started?

Author
Message
Mark Garrett
Reviewed AGK on Steam
18
Years of Service
User Offline
Joined: 10th Jul 2005
Location: California, US
Posted: 10th Mar 2023 21:47 Edited at: 12th Mar 2023 03:44
Can an array save the names of a player for the next game even if the game is shut down and re-started?
or should I use a 'open to write to text-file' instead?

This game would just be for a family who reside in the same house, and not for online players.
And I want to have 4 players for the game and a way to edit or delete the names to add new names.
And when they re-start the game later, I want them to be able to choose their name on the main screen,
so they can continue where they left off, and with the same score as they left the game last time.

I have a hard time finding a sample program the tells how to do it.
I have finished the game, and this is my one 'sticking point'

I would appreciate the help very much if anyone show a sample program?


But here's what I have so far:



It is just a 'one player game' and the person plays against the computer.
So, I just need to save the names and the scores for each name. Because when the game starts again it is a 'table game' and re-organizes itself for the next 'round'.
So, yes, that's all I need is to save up to 4 names so they could, whoever wants to play it, just tap on their name again to go to the 'next round'.... that he left off.
Or to start a new round,(Level)
So, I need to save 3 things. the 'player name' and his 'Round_..(level)' that he's on and his current Total for that level.
Mark G.
Coding is bliss...
When I get a good idea.

Attachments

Login to view attachments
Steve Ancell
18
Years of Service
User Offline
Joined: 16th Feb 2006
Location: Brighton, East Sussex, UK
Posted: 11th Mar 2023 09:57
In my experience array info is lost when the program is terminated, you need to store the info into a file and load it back into the array when the program is started.
Mark Garrett
Reviewed AGK on Steam
18
Years of Service
User Offline
Joined: 10th Jul 2005
Location: California, US
Posted: 11th Mar 2023 14:14 Edited at: 11th Mar 2023 14:34
by file, you mean text file?
Quote: "you need to store the info into a file"
Steve Ancell
18
Years of Service
User Offline
Joined: 16th Feb 2006
Location: Brighton, East Sussex, UK
Posted: 11th Mar 2023 19:01
Yeah a text file, it can contain numerical, string or char codes and doesn't specifically need to have the .txt extention. I normally use the extention .dat for storing stuff such as level data.

I've attached a file example, ignore what I called it (ABC), I just chose a quick and dirty file name for the project file.
Steve Ancell
18
Years of Service
User Offline
Joined: 16th Feb 2006
Location: Brighton, East Sussex, UK
Posted: 11th Mar 2023 19:09 Edited at: 11th Mar 2023 19:10
I forgot to put the save bit in the code but there is a file already included, that's when the attachment finally appears. I do need to menstion that when writing to a file you will need the entire path and include "raw:" at the beginning of it. Something like "raw:C:\MyProjectFolder\media\MyData.dat"
Steve Ancell
18
Years of Service
User Offline
Joined: 16th Feb 2006
Location: Brighton, East Sussex, UK
Posted: 11th Mar 2023 19:14
If you don't include raw: and the complete path the data will be saved to (for example) " C:\Users\UserName\AppData\Local\AGKApps\MyProjectFolder\media"
Steve Ancell
18
Years of Service
User Offline
Joined: 16th Feb 2006
Location: Brighton, East Sussex, UK
Posted: 11th Mar 2023 19:29
The zip file I attached didn't show so here's a code example instead.


Mark Garrett
Reviewed AGK on Steam
18
Years of Service
User Offline
Joined: 10th Jul 2005
Location: California, US
Posted: 11th Mar 2023 21:43 Edited at: 12th Mar 2023 03:37
Thanks Steve Ancell,
That's really great, I think I'll try your version,
In makes more sense than my version.
and the file location part is very helpful too

I'm sure it will save me a lot of 'digging' and 'trial and error'.
I see some things in your coding that I overlooked already, I appreciate it.

.

Anybody else have something to contribute? if so, feel free to add a post.
I need all the help I can get in this area. Please, Thank you.
Mark G.
Coding is bliss...
When I get a good idea.

Steve Ancell
18
Years of Service
User Offline
Joined: 16th Feb 2006
Location: Brighton, East Sussex, UK
Posted: 12th Mar 2023 08:47
A couple of functions I rattled out might come in handy if you ever need a situation when you want to detect when any key is pressed or released, like transitioning on at the end of levels and gameover and cutscenes, etc...



Typical usage examle:
Steve Ancell
18
Years of Service
User Offline
Joined: 16th Feb 2006
Location: Brighton, East Sussex, UK
Posted: 12th Mar 2023 13:33 Edited at: 12th Mar 2023 13:33
If you ever get stuck feel free to PM me so I don't wreck this thread by going too far off topic, you'll be surprised what I can sometimes come up with considering I'm not professional. Most of it is just common sense.
Raven
19
Years of Service
User Offline
Joined: 23rd Mar 2005
Location: Hertfordshire, England
Posted: 13th Mar 2023 01:25
Array.Save( Filename$ )
Array.Load( Filename$ )

Are the easiest approach...



This saves and loads from a Json File.
We can do the same with Types to and from Json formatted strings with the string = typedvariable.toJson() and typedvariable.fromJson( string ), if for example you wanted to handle the individual datasets rather than an array.

These files however are not (by default) stored in the Application\Media Folder... instead they're stored in the User\Application\Media Folder., which is hidden on most OS., although on Windows is easy enough to find.
I mention this, because the Json Format is readable in ANY text editor... so, you might want to add a layer of obfuscation or such for information you don't want tampered with.


Steve Ancell
18
Years of Service
User Offline
Joined: 16th Feb 2006
Location: Brighton, East Sussex, UK
Posted: 13th Mar 2023 02:58
@Raven

I never knew about array.save and array.load, I've never come across them in the AppGameKit documentation. I've just tried those two commands out for myself and have to admit that is a far easier way.

Thanks for bringing that to light.
nz0
AGK Developer
16
Years of Service
User Offline
Joined: 13th Jun 2007
Location: Cheshire,UK
Posted: 1st May 2023 00:07
I use the array.save function to make json skeletons for complex structures of data files I'm going to load in later. Just define the structure and make sure it has at least something in it, then save out.
I'm always forgetting a comma here and there in json files if I hand edit, so it's a nice shortcut.

Steve - look at the "arrays in version 2" section in the help, which shows some methods for arrays which aren't actual commands, so don't show up in the regular help.
Personally, I feel this was one of the biggest boosts to AppGameKit functionality when it was introduced, but as they are methods as opposed to commands, the info is a little bit buried in the help.

Login to post a reply

Server time is: 2024-04-26 11:46:47
Your offset time is: 2024-04-26 11:46:47