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:
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.
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
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.
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 ...
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!
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.
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).
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.