Howdy, Stranger!

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

Stopping custom div updates in SugarCube

edited October 2015 in Help! with 1.x
I use the code provided by TheMadExile's right hand side box to create custom divs on the page that can update every turn.

However, sometimes I only want them for limited uses. For example, I have one that only does anything on the game title screen.

But with the code it will keep checking every turn to see if any more updates come. This strikes me as slightly wasteful. Is it a problem, or is there any way to stop the check each turn?

Though I suppose if someone wanted to go back to the title screen it would need to be active again so it probably shouldn't be disabled.

Comments

  • It's probably not an issue to let them fire each turn, however, stopping them should also not be too much of an issue (especially ones that only need to be single-use).

    Code?
  • edited October 2015
    Pretty simple code, just this in script passage then a passage named Titles that has <<if>> statements hooking into passage tags.
    postrender["updateTitles"] = function () {
    	setPageElement("titles", "Titles");
    };
    
  • edited October 2015
    Is that supposed to be a single-use task?

    Regardless, to create a single-use task, all you need to do is to have the task delete itself. For example, a single-use postrender task:
    postrender["yourTaskName"] = function (content, taskName) {
    	// task code here…
    
    	delete postrender[taskName]; // single-use task
    };
    
    Just ensure you're using the correct parameter list (prerender & postrender have two, the other task objects only one).


    For tasks which are multi-use, then you can have the task simply return early if conditions are not right, thus bypassing whatever it is they normally do. For example, a postdisplay task which contains an early return:
    postdisplay["yourTaskName"] = function (taskName) {
    	if (/* skip task condition is true */) { return; }
    
    	// task code here…
    };
    


    You can also combine them in various ways. For example:
    postrender["yourTaskName"] = function (content, taskName) {
    	// task code here…
    
    	if (/* final task condition is true */) {
    		delete postrender[taskName];
    	}
    };
    
    And:
    postdisplay["yourTaskName"] = function (taskName) {
    	if (/* remove and skip task condition is true */) {
    		delete postdisplay[taskName];
    		return;
    	}
    
    	// task code here…
    };
    
Sign In or Register to comment.