Fixed spawners that spawn a single item among four options?

0 favourites
  • 5 posts
From the Asset Store
Footsteps SFX Four contains 400 sounds of steps and jumps on different surfaces.
  • Hi, guys! I've been struggling with a small project here. I'll try to be as concise as possible:

    - My stage is a maze, and you have to collect four different items inside it in order to open the exit door.

    - There should be only one instance of each item in the maze.

    - I created multiple instances of a spawner around the maze. They have fixed locations.

    What I'm struggling with is

    - To make four of these spawners (picked randomly) spawn a different item each

    - Make the spawners stop after all four items are spread around the maze.

    If I had a Jarvis, I would ask him something like "at the beginning of the stage, pick four of these spawners randomly and each one should create a different item", but I don't know how to put this into logic... Any thoughts? Any help would be really appreciated!

    Tagged:

  • Using an instance variable on the spawner object, something along the lines of :

    Pick a random instance of spawner, where instance variable is not set to 0 (default/empty), set var to 1.

    Repeat this for 2, 3 and 4. You can use a for loop for 1 to 4 and use loopindex as the variable which will be 1,2,3,4 or just add 4 events top to bottom and they would run in sequence.

    Then you have 4 spawners each randomly set to 1, 2, 3, 4.

    Add logic to make 1 relate to a particular item, 2 is another item etc

    Or if the item names are known and its easier with text, set the instance variable to a string and say where instance variable is blank/"", pick a random instance of spawner and set to item1name etc and repeat 3 more times.

  • Ok, so after a lot of trial and error, I solved it but it really feels like I took more steps than necessary for it, 100% improvise:

  • Using an instance variable on the spawner object, something along the lines of :

    Pick a random instance of spawner, where instance variable is not set to 0 (default/empty), set var to 1.

    Repeat this for 2, 3 and 4. You can use a for loop for 1 to 4 and use loopindex as the variable which will be 1,2,3,4 or just add 4 events top to bottom and they would run in sequence.

    Then you have 4 spawners each randomly set to 1, 2, 3, 4.

    Add logic to make 1 relate to a particular item, 2 is another item etc

    Or if the item names are known and its easier with text, set the instance variable to a string and say where instance variable is blank/"", pick a random instance of spawner and set to item1name etc and repeat 3 more times.

    I just saw your version after posting mine. Thank you! I'm going to give it a go :)

  • Try Construct 3

    Develop games in your browser. Powerful, performant & highly capable.

    Try Now Construct 3 users don't see these ads
  • Nice, your method seems fine too for a simple spawning. If you want to keep the spawners around you could set an instance bool hasItem to true so it's not picked again rather than destroy. There are many approaches for this kind of thing :)

Jump to:
Active Users
There are 1 visitors browsing this topic (0 users and 1 guests)