0 votes
by (120 points)

Hello,

I've got a rock climbing game going. There's a route up a cliff I'm calling $bambi. Bambi consists of three rock climbing "holds," each containing different properties that affect the player. 

<<set $bambi to	[{
		id : 1,
		type : "jug",
		pump : 2,
		tension : 1,
		sweat : 3,
		attention : -2,
	},
	{
		id : 2,
		type : "jug",
		pump : 2,
		tension : 1,
		sweat : 3,
		attention : -2,
	},
	{
		id : 3,
		type : "jug",
		pump : 3,
		tension : 2,
		sweat : 1,
		attention : -2,
	}]
	>>

The player starts on the ground and can choose one of four actions. Each action will have a different affect on the players stats, based on the hold that he is on. I know how to use pluck() to choose id 1, 2, or 3 at random, but I actually want them to be called in order, id 1 first, id 2 second, id 3 3rd. Is there a method I could use to accomplish this? 

Please let me know if I'm not being clear or can provide additional information.

2 Answers

0 votes
by (68.6k points)

It sounds like you want <Array>.shift().

0 votes
by (44.7k points)

You can access them by using $bambi[0], $bambi[1], and $bambi[2].  The array index (in the brackets) tells you which member of the array you're using.  So $bambi[0].id will be equal to 1, because array indexes begin at zero, and that is the first element in the array.

The .pluck(), .shift(), and .splice() functions will remove those elements from the array and return that element value, but you don't need to remove them from the array to access their values.

...