0 votes
by (260 points)

So I'm here again, trying to piece together my "life sim" type game. Working through an area that requires the players to change clothes in a locker while they do something, then coming back to put the clothes back on. 

 

This wouldn't be a problem if I didn't have lots of clothing options for my players. 

 

I've tried to get around this by "storing" the variable output into another variable:

<<set $lastWornClothes = { passage: "$playerClothes.passage", desc: "$playerClothes.desc", picture: "$playerClothes.picture"}>>
<<set $lastWornUnderwear = { passage: "$playerUnderwear.passage", desc: "$playerUnderwear.desc", picture: "$playerUnderwear.picture"}>>
<<set $lastWornShoes = { passage: "$playerShoes.passage", desc: "$playerShoes.desc", picture: "$playerShoes.picture"}>>

So here, it takes the player's currently worn variables, and stores them. This works fine, and allows me to change clothes in the locker, and then come back.

 

However, when I attempt to reverse this:

 

[[Change back into your street clothes.|Locker][$playerClothes = { passage: "$lastWornClothes.passage", desc: "$lastWornClothes.desc", picture: "$lastWornClothes.picture"}]]

I get an error. That reads: 

 

Error: <<print>>: bad evaluation: Maximum call stack size exceeded

 

In this instance, <<print>> is only showing <<print $playerClothes.desc>> or <<print $playerClothes.picture>>

 

I'm not sure what I'm doing wrong here.. I'd ideally like to have a single passage that I can use to "put everything back on" without having to have my players click back through all the various outfits. Honestly, it's now being referenced in so many places that I'm starting to lose track where I'm putting a "wardrobe" inventory that needs to be added to in the event I add new clothes.

 

Is there a simpler way of doing what I'm trying to do?

1 Answer

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

You don't state what the initial values of your $playerClothes, $playerUnderwear, and $playerShoes variables look like, so I will assume they contain an object value similar to the following.

<<set $playerClothes to {
	passage: "the-name-of-a-passage",
	desc: "a description",
	picture: "the-name-of-an-image-file"
}>>

 

SugarCube has a clone() function which you could use to achieve the effect you want.

<<set $lastWornClothes to clone($playerClothes)>>

... and you can test that the two variables now reference two different objects with 'equal' values and that updating one of the two objects doesn't effect the other like so:

Before changing current passage of playerClothes:

playerClothes passage: $playerClothes.passage
lastWornClothes passage: $lastWornClothes.passage

<<set $playerClothes.passage to "some-other-passage-name">>\

After changing current passage of playerClothes:

playerClothes passage: $playerClothes.passage
lastWornClothes passage: $lastWornClothes.passage

You can also use the same clone() function within your Setter Link.

[[Change back into your street clothes.|Locker][$playerClothes to clone($lastWornClothes)]]

 

by (260 points)
edited by
Nevermind that comment. Figured out it works like I wanted it to! Yay!
...