Hi all,
My first post in here.
I've been poking around to see if I can create a few dozen rooms in Twine that don't have links, but just act as a pool for some Javascript to pull from.
For example if I want to create the Minotaur Labyrinth, and have 200 possible room descriptions but only want 100 in a given playthrough and want the labyrinth to be generated dynamically in javascript.
Can I jump into the first passage, have the link hook out to the javascript and get passed to where the javascript says the next room is, rather than creating hardlinks?
Twine 2.0.8, SugarCube 2.0.0-beta.8, Javascript
Platform: Windows
Comments
So if you use code to randomly determine the target passage titles to go to then you could use code like the following to display the links: ... you could also include code to determine the associated Link Text to show for each of the above links.
It is a good idea to procedurally generated the maze (the list of passages involved and exits/entrances of each of those passage) at the start of the story that way you can use path checking to make sure that the player is not going to be stuck travelling between a small number of passages. Another hard part when creating a procedurally generated maze is making sure that if the direction of traversal is reversed that the traveller ends up in the same room that they just left.
eg. If the player goes from room A to B by going in a direction, then the direction to choose to travel back to room A should make sense, unless you like the text "You are in a maze of twisty little passages, all alike".
Just to keep things consistent.
The idea of reversing traversal and having it remember a number of steps backward (not just layout) is a cool idea So you could mark a room with an inventory item and then create a stack that tracks your movements and pops rooms off to another stack to go backward.
I could just store that marked room in a variable, but if there are any wandering creatures or timed events I might want turns consumed in the traversal back.
So, in my test system I have Javascript populating an array with the target rooms, then using a random number generator to pick which room a teleporter pedestal will send me to
But I've tried cheating the above sample by doing the following: Hoped that would work, but it did not. On the plus side my debug alerts that I added to my java show that the room selector is working.
I guess my option now would be to just add paragraphs for all potential target rooms and put conditionals on which one gets displayed depending on the value of $pedestalTarget.
Unless there's a sneakier way to do it with less code.
For those curious I will record a video in a moment showing what I'm doing
https://youtube.com/watch?v=TZ4DaCaoJLA&feature=youtu.be
You also don't need/want to be generating your random integers that way. Use the built-in random() function.
In your Story JavaScript, do the following instead:
Furthermore, unless you need the random number for something other than selecting a member from randomNumber, then you could simply use the built-in either() function or the
<Array>.random() method. For example:
Also, you probably don't need to make a copy of $pedestalTarget within your passage, simply use it directly within the link. For example:
EDIT: Alternatively, you could just assign the list of pedestals to a story variable and randomly choose right at the link. For example: (in Story JavaScript) Then in your passages: