Skip to main content

Indie game storeFree gamesFun gamesHorror games
Game developmentAssetsComics
SalesBundles
Jobs
TagsGame Engines

Simple Inventory Hack

A topic by greendad37 created Sep 08, 2021 Views: 141
Viewing posts 1 to 1
(+1)

This is a simple inventory hack that I am using.

In the starter template, I added the following code to div id = "start"

#do story = {}; inventory = {}; health = {}; 
#do story.title = "Generic Ramus Template"; inventory.book = false; health.food = 10;
#do localStorage.setItem("_story", JSON.stringify(story));
#do localStorage.setItem("_inventory", JSON.stringify(inventory));
#do localStorage.setItem("_health", JSON.stringify(health));

Throughout the story, I add and change inventory and save it to localStorage.

To display the inventory, I added the following code in the footer section after the moves and score lines:

<a href="#" onclick="return show_inventory(this);">Inventory</a>
 
<script type="text/javascript">
function show_inventory(node) {
displayHealth = {}; displayHealth = JSON.parse(localStorage.getItem("_health") ); alert("Your food level is " + displayHealth.food) ;
}
</script>

I'm sure there are better ways to do this, and look forward to seeing suggestions in the comments.