0 votes
by (1.1k points)

So I'm looking for a way to modify specific member-based arrays, for example.

Clothing being used.
<<set $Dressed_clothes = {
	top: ['White T-shirt']
}>>
List of top clothes available on inventory.
<<set $player_Tops = ['Black T-shirt', 'Black top']>>

And on the wardrobe menu.

Upper body:<<= $clothes.top[0]>>
Now the area of shirts and tops traversing the array of clothes of this class available, and setting them as used.
<<for _i, _tops range $player_Tops>>\
	[[_tops|Closet]]<br>
<</for>>\

In that part I'm a little lost, it's done in some parts, first bring the used clothes to the array of available clothes removing it from the array, and then put the selected clothes in place of the used clothes, the same. I tried a push and shift scheme but they are not exact, maybe splice()? I'm still getting acquainted with JS.
Note: I would like to know this in JS as well.

1 Answer

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

If the character is always wearing a shirt, then it's probably best to just swap them.  Something like:

<<set _tmp = $clothes.top[0]>>
<<set $clothes.top[0] = $player_Tops[_topIdx]>>
<<set $player_Tops[_topIdx] = _tmp>>

where _topIdx holds the index of the top to swap to.

If you want the currently worn top to become the last top listed in the $player_Tops array when changing tops, then you could do:

<<set $player_Tops.push($clothes.top[0])>>
<<set $clothes.top[0] = $player_Tops.deleteAt(_topIdx)[0]>>

Because the .deleteAt() method returns an array, you have to put the "[0]" at the end to get the first (and in this case, only) element in that array.  See the SugarCube array method .deleteAt() for details.

The answer is essentially the same in JavaScript, except with the references to the SugarCube variables being changed accordingly.

Hope that helps!  :-)

...