Howdy, Stranger!

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

2 questions about manually creating checkpoints in Sugarcane

Undo will not work for me because I use setTimeout() timers which should be reset manually if the user goes back. So I need to create a list of checkpoints which should grow while the users progresses. I want to place them in StoryMenu.
So, question 1: how to change StoryMenu from the game? I can do something like
<<set $addload=
function()
{$chkpnts.add(state.history[0].passage.title); /*$chkpnts is an array of passage names*/
 new Wikifier(StoryMenuObject, "[[Checkpoint "+($loads+1)+"|"+$chkpnts[$loads]+"]]");
 $loads++;
}
>>
but what should I write instead of "StoryMenuObject"?

Question 2: How to restore the variables? Will
$chkpntsvars[$loads]=state.history[0].variables
and later, executed by a click in StoryMenu,
state.history[0].variables=$chkpntsvars[$selected]
work?

Comments

  • For the first question, try something like the following:
    document.getElementById('storyMenu')
    
  • For the first question, try something like the following:
    document.getElementById('storyMenu')
    
    Although it adds the line to storyMenu, when the function ends, this line disappears again
    <<set $addload=
    function()
    {$chkpnts.push(state.history[0].passage.title); 
     new Wikifier(document.getElementById('storyMenu'), "[[Checkpoint "+($loads+1)+"|"+$chkpnts[$loads]+"]]");
     $loads++;
    }
    >>
    
    <<set $addload(); alert("pause 2");>>\
    Text text text
    
    While "pause 2" is shown, I see the correct new line in the left panel; after I click "OK", it disappears.
  • The sidebar elements are dynamically updated each time you navigate passages.
  • The storyMenu element is updated via the Tale.setPageElements function which is called near the end of the History.display function which I believe is the function used to display the current Passage.

    And I believe this is why your update to the storyMenu element is disappearing, because it is being overwritten with the current contents of the StoryMenu passage.

    I am curious why you are assigning Javascript functions to $variables instead of creating custom macros.
  • yunyun
    edited March 2016
    Yes, this variant inserted in StoryMenu works:
    <<silently>>
    <<set $showchkpts=
    function()
    {for (var i=0;i<$chkpnts.length;++i)
     new Wikifier(document.getElementById('storyMenu'), "[[Checkpoint "+(i+1)+"|"+$chkpnts[i]+"]]<br>");
    }
     >>
    <<endsilently>>
    Checkpoints:
    <<set $showchkpts()>>
    

    So, the more important problem remains: how to save and restore the variables? I've checked already - direct assignment like in my initial post doesn't work.

    I prefer function calls to macros. More convenient both to write and to use, e.g. I can insert them in a link, like
    [[Goto 29|29][$playsound("switchup.wav")]]
    
  • "Rewind" does ALMOST what I need, but I need 2 significant changes: entering my own checkpoint names in the rewind menu and running my own function (which will reset the timers and stop sounds) before going to the corresponding passage. Is there a way to modify Sugarcane standard rewind?
  • The Interface.buildSnapback() function builds the menu that appears when you click on the Rewind link, currently each menu entry is an excerpt of the bookmarked passage's content.
    b.innerHTML = state.history[a].passage.excerpt();
    You could modify the story format's header.html file so that that line of code used the passage's title instead.
    b.innerHTML = state.history[a].passage.title;
    

    re: Running your own Callback function:
    The buildSnapback function currently uses the back macro (defined here and extended here) to return the story to the selected menu item, you could either extend or replace the existing back macro with your own. The existing back macro can be extended in a script tagged passage like so:
    macros['back_original'] = macros['back'];
    
    macros['back'] = {
    	labeltext: macros['back_original'].labeltext,
    	handler: macros['back_original'].handler,
    	onclick: function(back, steps) {
    		// Call the original back macro's onclick.
    		macros['back_original'].onclick(back, steps);
    
    		console.log('extended back macro onclick');
    		// Your code would replace the above console.log
    	}
    };
    
  • yunyun
    edited March 2016
    b.innerHTML = state.history[a].passage.excerpt();

    You could modify the story format's header.html file so that that line of code used the passage's title instead.

    b.innerHTML = state.history[a].passage.title;
    Thanks! Only it's in header.js, not .html.
    onclick: function(back, steps) {
    		// Call the original back macro's onclick.
    		macros['back_original'].onclick(back, steps);
    
    		console.log('extended back macro onclick');
    		// Your code would replace the above console.log
    	}
    
    I think my code should go before 'back_original', not after?
    However, I found another way: as I have prerender() already, I added my code there for the passages marked with "bookmark" tag.
Sign In or Register to comment.