+1 vote
by (1.4k 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
by (63.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. 

by (1.4k points)
This is exactly more than I had hoped for! How would you format it for the <<timed>> macro?
by (44.7k 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.

by (1.4k 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.

...