Create an inventory

Easily manage the inventory of objects collected in your serious game

Create an inventory of items collected in a serious game

No more hassle!

Simplify the handling of key objects by reducing both the number of variables used and the number of triggers to be programmed.

Customer Case


To highlight the problem, we're going to use as an example a customer case that many developers have encountered at least once.

Situation In a serious game on "building evacuation procedures and safety", a client wanted the players to each have several "pockets" in their "rucksacks" to collect different key objects from several different categories.
Conditions Players can start solving a puzzle as soon as they have 4 out of 5 objects in a given category.
Needs
  • Be able to identify objects as belonging to a category and
  • Be able to identify objects as recovered or not.

As you can see, the scenario is complete. A major challenge!

Before Nuggets


Development would have required the creation of a large number of variables, both in terms of boolean variables for each object to be found and numerical variables for each category.

In addition, we would have had to manage all the triggers that needed to be created for retrieving objects, accounting for objects retrieved for each category, unlocking puzzles at the right time, and so on.

The complexity of developing triggers would also have been a source of bugs...

Featuring Nuggets


Prerequisites


  • Master the use of operating expressions provided by the LocalTrack feature;
  • Set your `.STORY' file to use LocalTrack :
    • create a process variable and a result variable.
      For the article, we'll use InventoryTracking and InventoryResult.
    • create the trigger that will manipulate these two variables.
Storyline trigger
When 'InventoryTracking' changes
- Execute 'JavaScript'
    If 'InventoryTracking' ≠ value '(Empty)'
JavaScript
LocalTrack.parse('InventoryTracking','InventoryResult');

For further information, please refer to page « LocalTrack ».

We will not include the conditions If 'nuggetsLoad' = value 'True' and If 'isOnline' = value 'True' in the triggers that illustrate the article.

For your development, think about implementing them.

How it works


Fortunately, with Nuggets' LocalTrack feature, we can simplify this problem tremendously.

We will keep only the "category" variables and the LocalTrack operating expressions will drastically reduce the number of triggers we need to create.

The first step is to set out the list of categories and objects in a table.

Index Category Cat_1 Category Cat_2 Category Cat_3
1 Item 1.1 Item 2.1 Item 3.1
2 Item 1.2 Item 2.2 Item 3.2
3 Item 1.3 Item 2.3 Item 3.3
4 Item 1.4 Item 2.4 Item 3.4
5 Item 1.5 Item 2.5 Item 3.5

Next, let's create the category variables in Storyline's variables panel, along with an additional Categories variable which will monitor completed categories, and a CategoriesBuffer variable.

Let's look at the triggers. This is where the magic of operative expressions comes into play.

Let's start by assigning a trigger to each of the objects to be retrieved to **increment each of the corresponding Categories variables.

Storyline trigger
When the user clicks 'Button Item 1.1'
- Set 'InventoryTracking' to value 'Cat_1+1' 

When the user clicks 'Button O 1.2'
- Set 'InventoryTracking' to value 'Cat_1+2' 
// ...
When the user clicks 'Button O 2.1'
- Set 'InventoryTracking' to value 'Cat_2+1' 
// Etc.

Next, in order to monitor the "category" variables without having to duplicate the triggers each time an object is found, we're going to place the triggers on the applied layout of the slide mask used.

Storyline trigger
When 'Cat_1' changes
- Set 'InventoryTracking' to value 'Cat_1!1' 
- Set 'CategoriesBuffer' to variable 'InventoryResult' 
- Set 'InventoryTracking' to value 'Categories+1'
    If 'CategoriesBuffer' >= value '4'

When 'Cat_2' changes
- Set 'InventoryTracking' to value 'Cat_2!1' 
- Set 'CategoriesBuffer' to variable 'InventoryResult' 
- Set 'InventoryTracking' to value 'Categories+2'
    If 'CategoriesBuffer' >= value '4'
// Etc.

Finally, for each category, we check whether the Category variable has been modified.

Storyline trigger
When the timeline starts on 'this slide'
- Set 'InventoryTracking' to value 'Categories?1'
- Set state of 'Button - Quiz 1' to 'Normal'
    If 'InventoryResult' ≠ value '0'

When the timeline starts on 'this slide'
- Set 'InventoryTracking' to value 'Categories?2'
- Set state of 'Button - Quiz 2' to 'Normal'
    If 'InventoryResult' ≠ value '0'
// Etc.

When 'Categories' changes
- Set 'InventoryTracking' to value 'Categories?1'
- Set state dofe 'Button - Quiz 1' to 'Normal'
    If 'InventoryResult' ≠ value '0'

When 'Categories' changes
- Set 'InventoryTracking' to value 'Categories?2'
- Set state dofe 'Button - Quiz 2' to 'Normal'
    If 'InventoryResult' ≠ value '0'
// Etc.

Variations


Let's imagine that it's not a number X out of a total of Y items that triggers access to an enigma, but several specific items. For example, items 1.1, 1.3 and 1.4.

Here again, it's the power of operative expressions that will come in handy. And more specifically, binary operational expressions. As we're going to be working with binary expressions, we're going to try to keep things simple so that you don't get lost.

Let's take the table above and look at the Cat_1 column.

Let's add a Binary column which will give us the value of the bit at the corresponding index in decimal base. To put it simply, this corresponds to 2index (2 power index) and let's calculate the sum of the decimal values of the required items.

Binary Index Category Cat_1
21 = 2 1 Item 1.1
22 = 4 2 Item 1.2
23 = 8 3 Item 1.3
24 = 16 4 Item 1.4
25 = 32 5 Item 1.5

26

We then only need to adapt the trigger present on the applied layout of the Slide Master used.

Storyline trigger
When 'Cat_1' changes
- Set 'InventoryTracking' to value 'Cat_1&26' 
- Set 'CategoriesBuffer' to variable 'InventoryResult' 
- Set 'InventoryTracking' to value 'Categories+1'
    If 'CategoriesBuffer' = value '26'

Observe the elegance of the change!

Cat_1&26 filters indexes 1, 3 and 4 into the number stored in Cat_1 and sums the values of each retained index, whether they are equal to 0 or the decimal value 2index. If the sum does not equal 26, the enigma is not unlocked.

Once you've mastered the operative expressions, you'll be able to adapt them again and again. Don't hesitate to explore the possibilities!