+2 votes
by (180 points)

Hi guys!

I'm writing a game with Sugarcube 2.18.0 and I need some help. 

In my game, the player visits a house with many rooms. In each room, the player can 'remember' memories. I've designed it such that each memory is a passage, and every time the player clicks 'remember', a random passage is chosen (i.e. a random memory is displayed.)

For example, when the player choses to enter the garden:

<<set $Garden to either(
    'Before my piano recital',
    'CNY Sparklers',
    'Hanuman',
	'December 9th 2012',
	'May 23rd 2012'
)>>

Would you like to take a walk around the <<link 'garden' $Garden>><</link>>? 

So when the player clicks the link 'garden', a random passage/memory of the garden will be displayed. 

From there, I'd like to make it such that the player can choose to 'remember' another memory, or move on to the next room. 

How can I make it such that the player does not revisit the same memory twice? Since the passages are picked randomly from the $Garden set. Is it possible to delete the current passage the player is on from $Garden set to prevent it from being picked again?

And once the player has finished running through all the passages in $Garden set, how do I then display a new passage (essentially telling them that there are no more memories in this room, and they have to advance to the next room.)

Hope I explained myself well enough. Any help will be appreciated :) 

1 Answer

+2 votes
by (8.6k points)
selected by
 
Best answer

Save the currently unvisited memories to a variable, but only if it isn't set yet.

<<set $gardenMemories = $gardenMemories || [
	"Before my piano recital",
	"CNY Sparklers",
	"Hanuman",
	"December 9th 2012",
	"May 23rd 2012"]>>

If there are no more memories in this variable, go to your special "No more garden memories" passage, else pluck one randomly and go there.

Would you like to take a walk around the <<link 'garden'>>
	<<if $gardenMemories.length === 0>>
		<<goto "No more garden memories">>
	<<else>>
		<<goto `$gardenMemories.pluck()`>>
	<</if>>
<</link>>? 

Remember to either tag the passage "nobr" or else join this code into one line to avoid too much whitespace.

by (180 points)
It worked perfectly, thank you so much! :)
...