Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Progress Bar. How to tell a player how many passages they haven't viewed.

edited October 2016 in Help! with 2.0
I wanted to ask how I would go about letting the player know what percentage of the game's passages they've visited? As a way of letting them know how much of the game's content they haven't seen (passages viewed) either at the end of the game or with a running total (progress percentage) on the side bar (preferabbly).

Basically a progress bar that lets the player know how many passages he hasn't yet visited to encourage a second play through or continued exploration.


Comments

  • edited October 2016
    Which story format, and which version of it, are you using? The answer depends upon this. I'm assuming Harlowe or SugarCube, from the mention of a "side bar", but the answers for each of those will be different.

    EDIT: A complication, regardless of story format, would be if you allow any passages to be visited more than once. That would make things a bit dicier.
  • edited October 2016
    Yea,I would have passages revisited. How about a counter variable that divides the number of unique passages visited by total passages with progress being measured as a percentage of all passages explored.

    The dicey part would be as you mentioned, how do I make the counter tick up only once per unique passage visited..


    Also I'm using default sugarcube 1.3 but I can make the switch to sugarcube 2.0 if necessary.
  • Also I'm using default sugarcube 1.3 but I can make the switch to sugarcube 2.0 if necessary.
    Switching to SugarCube v2 would be easier, if you can swing it.
  • The following SugarCube module should probably do what you want. It should work in either major version.

    CODE: (Twine 2: goes in Story JavaScript; Twine 1: goes in script-tagged passage)
    /*! storycompletion module for SugarCube */
    !function(){"use strict";function tallyInit(){_total=Object.keys(_Story.passages).filter(function(name){return!_skipPassages.includes(name)}).filter(function(name){var curTags=_Story.passages[name].tags;return!_skipTags.some(function(tag){return curTags.includes(tag)})}).length}function tallyUpdate(){var completion=_State.active.variables._completion,curPassage=passage(),curTags=tags();completion.list.hasOwnProperty(curPassage)||_skipPassages.includes(curPassage)||_skipTags.some(function(tag){return curTags.includes(tag)})||(completion.list[curPassage]=!0,++completion.count)}function tallyCount(){return _State.active.variables._completion.count}function tallyTotal(){return _total}function tallyPercentage(digits){return(100*tallyCount()/_total).toFixed(null!=digits?digits:1)+"%"}function tallyToString(digits){return tallyCount()+"/"+_total+" ("+tallyPercentage(digits)+")"}var _skipPassages=["PassageDone","PassageFooter","PassageHeader","PassageReady","StoryAuthor","StoryBanner","StoryCaption","StoryInit","StoryMenu","StorySettings","StoryShare","StorySubtitle","StoryTitle"],_skipTags=["Twine.image","skip"],_State="undefined"!=typeof State?State:state,_Story="undefined"!=typeof Story?Story:tale,_total=0;_State.active.variables._completion={list:{},count:0},predisplay["completion-tally-update"]=function(){tallyUpdate()},window.Completion=Object.freeze(Object.defineProperties({},{total:{value:tallyTotal},count:{value:tallyCount},percentage:{value:tallyPercentage},toString:{value:tallyToString},all:{value:tallyToString}})),tallyInit()}();
    
    NOTES:
    The module creates a global object named Completion and a story variable named $_completion, since the completion data must be a part of the history. While you will use global, you should never need to think about the story variable.

    You may manually exclude passages from the completion tally by tagging them with skip. It automatically excludes most special passages so you don't have to worry about that.

    You may add new passages to your project and the module should pick them up without issue.

    WARNING: Removing passages, even by rename, will invalidate existing completion data—i.e. the completion state of existing saves will be invalidated.

    USAGE:
    → To print the total number of passages considered for completion.
    <<print Completion.total()>>
    
    → To print the number of passages which have been visited.
    <<print Completion.count()>>
    
    → To print the completion percentage (format: "###.#%").
    <<print Completion.percentage()>>
    
    → To print the total number of passages, passages which have been
    → visited, and completion percentage (format: "#/# (###.#%)").
    <<print Completion.all()>>
    

    The total and count values could be used to do something fancier—e.g. a graphical progress bar—if you wished.
Sign In or Register to comment.