2017년 7월 30일 일요일

How can I save a numerical value to a file and recall it to a variable?


I am intending on creating a game similar to the popular Cookie Clicker. I saw a thread asking about how to create an upgrade shop, but I am interested in a save mechanism. For example, I download this app and collect 54 coins. I shut off the app, it is saved, and when I start the app back up, the 54 coins are still there for me to add to. Correct me if I'm wrong, but I thought the easiest way to do it was to save the value to a file, then recall it to a variable to change it afterwards. Any help will be much appreciated.

--
You have two options:
1) Save to a TinyDB.  In this case, you do not save to a file, the TinyDB is internal to and part of the app.
2) Save to a csv file or a text file.    You can save multiple values in a csv.  Retrieve the csv or text file when the app starts and it will have any value(s) saved when you save the file.    Use the File component to read from and write to the file.

--
TinyDB is the simplest, with no delay between asking for the value
and getting it back.

See here for three TinyDb examples.

--
It does not look like you have used the forums yet, as a search using the search box above would have returned several threads about this topic.

Advice: Before posting, it's a good idea to search in this forum. Many others have likely run into problems similar to yours. How to search see screenshot.
Josh replied by eMail..threads are automatically terminated for lack of activity after two weeks... why did it take so long to reply Josh?

Your note:
This seems to be the best idea, but how exactly would I go about doing this? It's not the theory, it's more the work.


As suggested by others, the solution is somewhere in the Forum.

Here is some specific reading material

Tutorials:


the AI2 free online eBook   http://www.appinventor.org/book2 ... the links are at the bottom of the Web page.  The book 'teaches' users how to program with Ai2 blocks.




How do you do some basic things?    http://www.appinventor.org/content/howDoYou/eventHandling



=====
Lists
Sajal's example    List Blocks On App Inventor

Hossein's example    List & List Manipulation



List of Lists

========================
TinyDB
ABG's example    Build Your Own DB - Part 1   demonstrates filtering

Stephen's example    TinyDB - a persistent data solution


========================
FILE and CSV
FIle and csv's .... another possibility for storing and retrieving you leader board info....here are links to a lot of stuff about them 





You specifically need to read about the TinyDB but probably will benefit by most of this.   Sorry, there is no easy way to explain what you want to do Josh because you have to do it.  This stuff will certainly help.  What have you tried?

--

댓글 없음:

댓글 쓰기