Spawning sequential pickups for the player to collect

:information_source: Attention Topic was automatically imported from the old Question2Answer platform.
:bust_in_silhouette: Asked By NerdAlert

BLUF Sequential item Spawner that spawns only after the previous thing has been picked up. once all items are collected go to win screen.

Background I have followed the Godot intro 2d tutorial. I have added a spawner to display an item on the screen and when the player interacts with it the item disappears and a sound is played.

What I am trying to achieve I have created 7 identical sprites (except for colour) for the collectable object and I would like to Randomly Spawn the first colour and then once that is collected spawn the next one at a random location on the game area and so on. Once all 7 have been collected goto the win screen.

What I would like I don’t wont the code just a direction for research.

Thoughts I was thinking a list or dictionary? but I am unsure how to use these. Could I have one master pickup scene with all 7 area2d nodes with their associated sprites.

Any help would be much appreciated.

:bust_in_silhouette: Reply From: Inces

There is a nice built_in function for this, it is called shuffle(). So You can create an array with instances or paths or just integers associated with your collectables. Every time Spawner is triggered it will shuffle() array and pop_front() 1st entry to be created into the scene. This will automatically remove it from array, so array will be smaller each time spawner is triggered. You can set the game to victory when spawner is triggered but array is empty.

If color is the only thing that is different among your collectables, You can use just one scene for all of them, that will have “color” variable. This way You can keep colors in the array instead of paths/nodes, and spawning would create instance of one scene and set its color to the randomized array entry.

Does this help ?

:bust_in_silhouette: Reply From: SnapCracklins

Actually, a variable is probably fine here just for tracking the item toward a completion.
I know you said no code so I’ll fly blind here:

var pickupTotal = 0

Then have:

pickupTotal += 1

Every time you pick up an object.
Then run a function that checks this:

func _process(delta):
    if pickupTotal == 7:

Or whatever code you are using for transitions once you hit the total.

As for the random spawning, you don’t likely want to go “that” random because then your objects could end up in weird places. So make about 10-20 or more places where they could spawn and then some sort of code to randomize in which of those locations they show up.