+1 vote
asked by (890 points)
Hello wonderful people!

(Using SugarCube 2.21)

I thought it would be fun in a scene where you "die" to deliberately insert things (using <<timed>> delays) that cause error messages. But I only know of a few errors I can prompt, like "that passage does not exist" or "that audio track does not exist", and I was wondering if anyone knows of more, and how they would be prompted.

Thanks!

1 Answer

+2 votes
answered by (57.1k points)
edited by

You can use the throwError() function to throw custom errors to your heart's content.

@@#error;@@

<<script>>
    postdisplay['error'] = function (t) {
        delete postdisplay[t];
        throwError('#error', 'No player character.', 'You appear to be kind of mostly dead.  Sorry you had to find out like this.');
    }
<</script>>

Note that because the error message needs to target something on the DOM, you need to wait for the rendering to finish before you can do it.  A postdisplay task (as above) works, but so would a passage event, a link/button, or even a <<timed>> macro.

Note: This is an undocumented function, so it's not officially supported, and could change, be removed, be made unavailable, etc in future SugarCube versions. 

commented by (890 points)
This is exactly more than I had hoped for! How would you format it for the <<timed>> macro?
commented by (18.6k points)
edited by

This would work:

<<nobr>>@@#error;@@<<timed 3s>>
<<run throwError('#error', 'No player character.', 'You appear to be kind of mostly dead.  Sorry you had to find out like this.')>>
<</timed>><</nobr>>

That will display the error after three seconds.  See the <<timed>> macro for details.

commented by (890 points)

Thank you guys! It worked like a charm!

Here is the finished product:

VValkabout

It is a proof of concept for making 3D environments in Twine.

Welcome to Twine Q&A, where you can ask questions and receive answers from other members of the community.

You can also find hints and information on Twine on the official wiki and the old forums archive.

See a spam question? Flag it instead of downvoting. A question flagged enough times will automatically be hidden while moderators review it.
...