0 votes
by (160 points)

Hi, I'm new to Twine and not great with JavaScript. I'm trying to make a maze puzzle game in the form of a "building" (inspired by Christopher Manson's MAZE), with room entrances offered as choices. Once the player has entered a new room, I want the room from which the player arrived to be "locked", with link text deactivated, until the player reaches it from a different path—meaning the player should not be able to go directly backward to a room that has just been visited, but can revisit if the room is offered as an option again at a later time. 

I poked around and the lastVisited function looks perfect for this since it can track how many clicks/rooms away from a particular Room X the player has gone. 

With a value of -1 being never visited Room X , 0 being in Room X, 1 being just past Room X, and 2 being two turns/clicks past the room, I'd want the link to Room X to deactivate if lastVisited("Room X") is equal to 1. For all other cases, if lastVisited("Room X") is less than 1 or equal to or greater than 2 the link should stay activated or be reactivated. This would have to work for each of around 20 rooms.

How would I implement this? 


1 Answer

+1 vote
by (44.7k points)
selected by
Best answer

It's probably easiest to use the previous() function inside of a widget.  So make a passage for your widgets (the name doesn't matter) and add the "widget" and "nobr" tags.  Then put this in that passage:

<<widget "Exit">>
	<<if $args[0] !== previous()>>
		<<if $args[1] === undefined>>

(Note: This will create a passage titled "$args[0", you will need to delete that passage for this widget to work.)

Now you can do something like this in your passages:

<<Exit "Room1" "North">><<Exit "Room2" "South">><<Exit "Room3" "East">><<Exit "Room4" "West">>

That will display something like this:


With those links going to Rooms 1-4, but if any were the previous room you were in then they won't be listed.

Hope that helps! smiley

by (160 points)

Thanks you! It works awesomely. What does the $args and the


mean (if it's not too complicated to explain)?

by (44.7k points)
edited by

"Args" is short for arguments.  And the number in the brackets is the number of the argument (starting with zero).

So when you call a widget like:

<<widgetName "argument1" 2 "argument number 3" $value>>

then $arg[0] will equal "argument1", $arg[1] is the number 2, $arg[2] is "argument number 3", and $arg[4] will be whatever the value of $value is.

For more information see the <<widget>> macro in the documentation.

So if you call:

<<Exit "Room1" "North">>



would be:


Which would show a link that displays "North", but clicking that link takes you to the passage titled "Room1".

See links markup in the documentation for details.

Hope that helps! smiley