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 / [SOLVED] How to write to file, and read from the same file later (on Ipad) ?

Author
Message
Mark Garrett
Reviewed AGK on Steam
18
Years of Service
User Offline
Joined: 10th Jul 2005
Location: California, US
Posted: 3rd Jul 2019 01:09 Edited at: 3rd Jul 2019 01:52
On I-pad, how could my video game record the last score of a game, and later, (like 1 month later or whatever), the player can retrieve it to see his last score?

Like, I know I could print it on the screen or whatever, if he presses a key.

But how could I code it so that the game will both write the score and then could retrieve it later? That is my problem. I keep getting error messages ...(File already exists) and (File already opened for writing).

Oh, here's the answer to that:



But now I have one more question....
What if I want to record player top 10 scores?
How do I write to 9 more lines below the first score?
Or, how can my code write to any line I want it to?
Is there a special 'line command' for files of this type?

The author of this post has marked a post as an answer.

Go to answer

fubarpk
Retired Moderator
19
Years of Service
User Offline
Joined: 11th Jan 2005
Playing: AGK is my friend
Posted: 3rd Jul 2019 02:08 Edited at: 3rd Jul 2019 02:19
This post has been marked by the post author as the answer.
you need an array of highscores

and can use for/next loop with the write command

you will also need to arrange them in some kind of order

myArray.sort() will sort them numerically

so when you do your for next loop


You will also need to remove the first element(sorted) and replace with a new higher score once you have 10 elements and a high score greater than the last
I prefer to use writeline and convert the int to string with str(myint) but then you would need an encryption
fubarpk
fubarpk on Itch...………...https://fubarpk.itch.io/
fubarpk on googleplay..https://play.google.com/store/apps/developer?id=fubarpk
Mark Garrett
Reviewed AGK on Steam
18
Years of Service
User Offline
Joined: 10th Jul 2005
Location: California, US
Posted: 6th Jul 2019 23:36 Edited at: 7th Jul 2019 01:06
Well, it's working out good. And the scores are sorting in their 'real-time' order. (First in, Last out), and I use 10 Text Objects to display them.

Thankyou
fubarpk
Retired Moderator
19
Years of Service
User Offline
Joined: 11th Jan 2005
Playing: AGK is my friend
Posted: 7th Jul 2019 01:05
If you save the scores as a standard text file its very easy for someone to modify it
not that it really matters unless you are planning multiplayer later on.
fubarpk
fubarpk on Itch...………...https://fubarpk.itch.io/
fubarpk on googleplay..https://play.google.com/store/apps/developer?id=fubarpk

Login to post a reply

Server time is: 2024-04-24 16:03:09
Your offset time is: 2024-04-24 16:03:09