0 votes
by (190 points)
Hey!

So I'm using Sugarcube 2.21.

My question is regarding arrays. And my problem right now is that I want to create an array with possible names to give to enemies. And when the enemies appear I want one of the names to be randomly selected (which I know I can do with the random() function). The thing is, how do I make sure that the name that is chosen doesn't get chosen again further down the line when the player is met again with an enemy? And that instead, another name is plucked from the array?

Also is it possible to make that happeneed with multiple enemies at once? I'm doing sort of a dungeon crawler, and what I'm wondering is if in one instance the player meets only one enemy, only one name is taken from the array. And then he keeps playing but this time he meets three enemies, and three names are taken from the array (that are no the same as the first one)??

I hope I'm not asking too much... I'd appreciate any help! :)

1 Answer

0 votes
by (23.6k points)
edited by

Look at this question and the answer given by @Chapel and @TheMadExile there. That should point you into the right direction.

 

If you really just want the names not be reused at any point, you can just use the <Array>.pluck() method to completely take the element from the array (that'll mean you'll eventually run out of names if there are more enemy encounters than elements in the array).

...