In Assigning badges to pages I covered what a script would look like that could generate a badge awarding environment. Typically you would create a UI to manage this, rather than doing it through scripts. However, here’s another approach using a spreadsheet to describe your questions and answers.

You will notice there are 5 tabs and they are used as follows. Take a look at the tabs and read the description below. The Spreadsheet is here if you want to copy it.
  1. panelsets. These are lists of collections of badges (described in the collections tab) that should be presented in response to a request for a panel set of the given id. Typically these would be badges that represented learnable topics on the page that holds the panel.
  2. collections. These are collections of badges (described in the badges tab) that would typically go together. A set of collections are referenced by a panelset and together are shown on a page. A collection can be referenced by multiple panelsets
  3. badges. These are badges that can be earned, and must appear in collection(s) to be accessible from a panelset. They refer to questionets (which appear in the questionset tab). These questionsets must be answered to qualify for a badge. A badge can appear in multiple collections.
  4. questionsets. These are a list of questions (described in the question tab), that would typically go together. A questionset can be associated with multiple badges
  5. questions. These are the questions and answers that would be combined into a questionset and associated with a badge. A question can appear in multiple questionsets

By splitting up the components in this way, questions, collections, questionsets and badges can be recombined in multiple ways depending on the topic the panelset refers to.

Creating the scriptdb

The badgeManager will take data from the scriptDB. The data in your sheet needs to be loaded into a scriptDB, but I provide a library to do that accessible in the mcpher library – see Using scriptDB. Once you have constructed the spreadsheet above, all you need is one line of code as below

Typically you would be using the scriptDB of the script that serves up the badge data, rather than the one associated with the sheet that defines the data, for a couple of reasons
  • You may not want to make this sheet public, or to publish it as a web app
  • You may have multiple sheets, or a UI, all of which modify the shared scriptdb that holds your badge data.

Taking the test

The badge set below selects one of the panelsets created from the spreadsheet discussed above.



The code

Here is the code that generates the scriptDB data from the sheet above.


For help and more information join our forum, follow the blog or follow me on Twitter .