Hello, all. Somewhat new to the more complex aspects of Twine, and I need some help with a problem I've encountered involving perspective and directional changes. I'm making a maze exploration game, and as it's set up now, each passage is a branching part of the maze, with the player being given multiple options on where to go depending on the layout of the maze (left, right, forward, back). The issue arises when taking into account the perspective of the person. Since directions like right and left are dependent on the person, i.e. if I turn left what was my left is now my forward, it's possible to walk to the same places in the maze but have everything a completely different direction relative to the player. Crude example below:
And this is the problem: how do I make it so each passage knows from which direction the player entered it so the directional options can be changed accordingly?
Thank you in advance for your help.
Comments
So in your first example the player starts facing up/north so <<set $pdirection to 0>>.
To get to the position in the second example they would of gone left,right,and about face, so that would be: Which results in $pdirection equal to 180, which indicates that the are facing down/south on your maze.
This is very helpful, but how would it all look in an actual passage? I'm trying to put what you posted into a setter link, but I keep getting error messages. I know this is probably horribly wrong. M srry.
That's a possibility. If I could help it I'd rather use the other way, but if the maze ends up being too large or too complex I might end up with the cardinal directions.
Well, for one thing, the keyword "set" is not needed in a setter link, or the close-macro-brackets. It should look more like: You also want to use the modulo operator to make sure the values don't get outside the valid range. Although personally I'd just as soon use 0-3 (with a % 4), since you don't need all those between-angles anyway.
Then, in each maze passage, you could just change the direction in your descriptions. It might be useful to have custom javascript functions for each cardinal direction, like a north() function that uses if statements to print either left, right, front, or rear, depending on the value of $pdirection. If you did that, you would also have to use a function for the direction change, like northChange(), so it could figure out the right direction to change in. Then your links would look more like: ...you might also be able to use other passages with the <<passagename>> macro instead of functions, but I haven't tried using that inside of a link.
If you don't have many unique features in any spaces in the map, you could also just use a single passage, and use an array to keep track of which spaces are connected, and check the array to see which directions are valid. You could probably find some examples in game programming tutorials. That would involve less passages and more javascript code, but you would also not be able to use the visual story view of Twine to view the maze.
edit:
Actually, if you do it the above way and every link is explicitly north/south/etc, and you're only changing the words, you don't have to do the add-modulo-thing. Just have $pdirection be a string, then your north() function would look like: And your link:
Passage 1: Passage 2: Passage 3:
Your problem stems from the fact that JavaScript does not, currently, have a true modulus operator. Instead it has the remainder operator (
%
), which is subtly different. So, it would be correct to say that the example you were given was flawed. I'd suggest the following instead.Add this to a
script
tagged passage: Then try the following instead of the sample you posted: