Create an inventory in App Inventor

I'm trying to create a text adventure game in AI and I want to implement an inventory system to it.
The problem I'm having now is that I can't transfer the list across the different screens.
This was what i was able to do:
The first screen:


The second screen:

Try changing all your blocks with a red cross to global invent2

Thanks for the suggestion. I did but it doesn't work...

Set global invent2 to the tinydb getvalue = Inventory/Topics in Screen2.Initialise

1 Like

It's tedious to keep global variables in sync with TinyDB.

Here's an alternative approach that dispenses with the global variables entirely:

1 Like

Can you point out which part I need to focus on?

Read the addTeamPlayer procedure, that adds a player to a team.
Notice how it only uses a local variable, not depending on any global variable, because it gets its data directly from TinyDB (through a procedure), updates the list, then stores it back into TinyDB.

1 Like

I'm sorry but I'm still confused, can you give me a simpler example. Also, do you know how to stop a global variable from creating an empty list after it's not empty. Thanks so much


Please export your project and post it here.

Here's a better version of my project
textadventure.aia (1.5 MB)

I went through your screens and blocks, to study the structure of your app.
I think you will be hitting a wall soon as you overload the capacity of the Blocks Editor and Builder with Screens and blocks.

You would gain headroom if you switched to a reusable List Picker loaded dynamically from various Media tables, like in this sample project: https://docs.google.com/document/d/1S8eZBKBvtFzafH51a3bKnw_iBVHRnjHaEY1Zbjzscb0/edit?usp=sharing

I also advise visiting https://www.scummvm.org/ to decide if you are more interested in just a glass of milk versus starting a dairy farm. At least study the structure of how they encode locations, items, choices, and events.

If you are planning on building your own general purpose adventure engine, you will need to write your own adventure interpreter, and store progress in different TinyDB Namespaces, like:

  • ItemLocations (tag = item name("bloody knife"), value = location ("Mr. Hargraves' body"/"evidence bag"/"crime lab")) (This is your requested inventory system)
  • LocationFocuses (tag = location("Dining Room"), value = list of adjacent locations ("Dining Room floor"/Dining Room Table/Mr. Hargraves' body/"kitchen"/foyer)
  • LocationContents (tag = location ("Mr. Hargraves' body"), value = list of items ("bloody knife", "ransom note", "loose change")
  • EventHistory (tag = eventName "The dog barked"), value = false)
  • EventRequirementLists (tag = eventName ("You are greeted by Mrs. Hargraves"), value = list("Arrived at Hargraves house", "Rang the Doorbell", location=doorstep) (* need a way to encode this)

Your blocks and designs, for the benefit of the other readers ...



Screen1



Screen4





Screen11

1 Like

First of all, I want to thank you for your efforts and suggestions, I tried to read and take note of the docs and everything that you write but this is a bit too complicated for me, as a beginner, to understand (specially the doc). My purpose is to make a simple game for personal reasons and I don't plan on being an expert at AI so if you could, can you please give me an example on how I may arrange the blocks? I just need to figure out how to store list into tinyDB and stop it from crating empty ones once there's data. Thank you!

If you do not want to store a value in tinydb or a list if it already contains something:

For a list:

image

For a tinydb entry:

image

1 Like

Thanks for helping but I'm looking for a way to stop creating an empty list when the list contains an item. The block "initialize global create empty list" will delete all the items in the global variable once the screen is opened, I assume.

You are asking to do something that does not need to be done!

If the list is empty, you have an empty list, if the list contains list items, do nothing.

That's a cost of using global variables in a multi-screen environment. They keep getting re-initialized as you re-open screens.

I find it simpler to work with data directly in TinyDB Namespaces, through procedures to hide their workings and to simplify the code.

Here's a sample Tinydb app (Fruit Stand) with no global variables and two TinyDB Namespaces (Cost NameSpace and Current Purchase Quantities NameSpace).

I want to make inventory management app for small business please help me

Welcome Chand.

Like this MIT App Inventor Gallery ?

or use the suggestions earlier in this discussion.

What have you tried? You could use CloudDB, FirebaseDB, a GoogleSheet as a database or several other options with App Inventor. Perhaps look at Databases

Here are some resources to help you learn to use the AI2 tools. A very good way to learn App Inventor is to read the free Inventor's Manual here in the AI2 free online eBook App Inventor 2 Book: Create Your Own Android Apps ... the links are at the bottom of the Web page. The book 'teaches' users how to program with AI2 blocks.

There is a free programming course here Course In A Box and the aia files for the projects in the book are here: App Inventor 2 Book: Create Your Own Android Apps

How to do a lot of basic things with App Inventor are described here: How do you...? .

Also look here App inventor español. Offline. Tutorial. Ejemplos. Instalación. Códigos. Juegos. Curso gratis de App inventor. and here Tutorial Index | Imagnity for more tutorials

Learn about components Component Reference
and visit the Library The MIT App Inventor Library: Documentation & Support Help>Library on the MENU

Here is an introduction to the accounting side of inventory management ...