Using a TinyDB to save progress

626 views
Skip to first unread message

JBK Games

unread,
Jun 6, 2015, 2:07:34 AM6/6/15
to mitappinv...@googlegroups.com
Hi, I'm currently making a very big app which I hope to release in a few weeks. I just have one last issue that I need a little help with...
In my app you can unlock new items, I have got all this sorted except for the part where I need to figure out how to save the progress. Example... if I unlocked the first 'item' then I exit the app, when I come back into the app I want the first item to be unlocked still, rather than having to unlock it again. Does anyone know how I can do this? I'm using MIT App Inventor 2 to program it if that helps. Please get back to me ASAP.

P.S. I apologise for being very unspecific with my app, I don't want to give the idea away ;)

Thanks,
JBK Games

Greg Jensen

unread,
Jun 6, 2015, 2:17:12 AM6/6/15
to mitappinv...@googlegroups.com
The TinyDB component allows you to save data on the device. If it's OK that you're game progress/state/preferences/etc.  are saved specific to a device and not a user then TinyDB is the simplest way. For whatever you need to save you simply use the TinyDB methods. Put TinyDB get value blocks in the screen1.Initialize block to set everything up when the app/game is opened. If you haven't already, check out the tutorials that use the TinyDB.

JBK Games

unread,
Jun 6, 2015, 2:19:18 AM6/6/15
to mitappinv...@googlegroups.com
Do you have any idea what else I would do to save the unlocked items and the still unlocked items?

Greg Jensen

unread,
Jun 6, 2015, 2:23:02 AM6/6/15
to mitappinv...@googlegroups.com
TinyDB is your local device storage component in AI2.  If your asking about alternatives to TinyDB then you could use the File component. It would be a lot more work tho.  

JBK Games

unread,
Jun 6, 2015, 2:28:47 AM6/6/15
to mitappinv...@googlegroups.com
Here's what I have,

On the screen1.initialize block I have set unlockable2.image to call unlockable2.getvalue the tag is Unlockable2 the valueIfTagNotThere is unlockable2.image
On the unlockable2.click (its a button) I have call unlockable2.StoreValue and the tag is Unlockable2 and valueToStore is unlockable2.image

Would this work?

Greg Jensen

unread,
Jun 6, 2015, 2:36:23 AM6/6/15
to mitappinv...@googlegroups.com
I think you're on the right track. You can only have ONE TinyDB in your app (it'll let you add more but they'll all be the same I think - never tried that myself).  Anyway... you probably want to name the TinyDB something more general or even just leave it as tinydb1.  Also remember you can have as many tags as you like and what you store in each tag doesn't have to be text or a value. It can be a list, time instant, color, or even a component. It's really quite flexible. 

JBK Games

unread,
Jun 6, 2015, 3:04:03 AM6/6/15
to mitappinv...@googlegroups.com
Really? How would I make one single tinydb be able to relate to all the unlockables? Are you able to help me sort this out?

SteveJG

unread,
Jun 6, 2015, 7:46:09 AM6/6/15
to mitappinv...@googlegroups.com
1) It appears you have several screens.  If the number of screens is less than or about ten, that is ok...more than ten screens might cause you app to become unstable.
so... you might do this.


Put a TinyDB control object on  Screen1, Screen2, Screen3 and so on.  You may leave the name of the object the default TinyDB1 on all the screens.   You will put several controls in the apps, one on each screen you use perhaps.   However, ALL of these objects refer to the same database.    If you name a tag on one screen   firstItem, you can recall it using the tag firstItem on ANY of the screens and if the value is true for firstItem (assuming it is a Boolean value), you can recall it on Screen3  using the tag  firstItem.

Try some blocks.

Here are several examples showing how you could use the TinyDB   

Steve

Taifun

unread,
Jun 6, 2015, 9:35:20 AM6/6/15
to mitappinv...@googlegroups.com
instead of storing each item in different tags in TinyDB, you also can work with lists and use only one tag


Trying to push the limits of App Inventor! Snippets and Tutorials from Pura Vida Apps by Taifun.         

Reply all
Reply to author
Forward
0 new messages