I wrote a short block of code to handle randomness in Nyx. I don't think it is the most streamlined way of doing randomness, but it works for me. I like it this way for technical reasons that I explain below.
So let's say you want to jump to 1 of 6 random pages, and you also need to be able to loop back and repeat the random jump again later.
First I write the last page that the user sees before the random jump, like I normally would.
No special code on this page. No randomness. This page might have text like, "Hmmm, what next..." I direct this page to a page called "jump4000" or something.
Next I write the 6 random landing pages like I normally would.
No special code on these pages. In this example, they are titled "g2liz11a", "g2liz11b", "g2liz11c", etc.
Next I create the "jump4000" page and paste this code into the "Script" tab:
Code: Select all
unset(4001#,4002#,4003#,4004#,4005#,4006#),delay(0hrs, range(4001,4006,'page'),style:hidden)
Next I create pages 4001 through 4006 by pasting this code into the "Script" tab:
Code: Select all
4001#page('',delay(0sec, g2liz11a#,style:hidden)); 4002#page('',delay(0sec, g2liz11b#,style:hidden)); 4003#page('',delay(0sec, g2liz11c#,style:hidden)); 4004#page('',delay(0sec, g2liz11d#,style:hidden)); 4005#page('',delay(0sec, g2liz11e#,style:hidden)); 4006#page('',delay(0sec, g2liz11f#,style:hidden));
All of these "code" pages are very simple. They have no text, no picture, no sound, and a 0sec delay that is "hidden."
Never look at jump4000 or pages 4001-4006 in the "Visual" tab of editor. It messes up the code if you do. If you need to edit the code, do it in the "Script" tab.
You don't need to look at the code pages in the "Visual" tab of the editor, however, because they have nothing you'd want to edit. Your story/tease is confined to normal pages that don't have any fancy code on them, so you can review and edit your text and pictures freely. The "jump" page and the numbered random "landing" pages are inserted via the "Script" tab where ever you need randomness. They have 0sec delay and the user does not see them go by.
That is how I accomplish the necessary unsets before random pages, while keeping the story easy to edit. It adds more pages than strictly necessary, but I like it because it's easier to debug and edit. Pages with text or pictures never have any special code on them.
I hope that helps. Good luck!
-lmind