Trying to spawn coins using a custom action or a function.

0 favourites
  • 6 posts
From the Asset Store
112 High-Quality Coins and Chest SFX specially crafted for video games
  • Hi. I have a level setup that spawns items like keys and coins, but for some reason it doesn't always spawn the coins when the action (or function) is called. Custom actions work for spawning the keys everytime but not the coins... is it because there are too many of them (450+) so it fails to execute?

    When I spawn the coins using "on start of layout" they spawn every time without fail, but I would like to have confidence that I can rely on actions and functions to work correctly so I want to know if I'm doing something wrong. Thanks.

    * scene_controller action 'Spawn Score'

    ----+ System: Pick all Score_Spawner

    -----> Score_Spawner: Spawn obj_coin on layer "a_objects" (image point 0, create hierarchy: False)

    Edit: It seems to happen because I start the 'Spawn Score' action at the end of another action (in a chain of actions). Calling the custom action from 'on start of layout' seems to work fine too.

    Here's the full group for reference -

    [Item Spawning]

    ----* scene_controller action 'Spawn Gold Key'

    --------+ System: Pick a random Object_Spawner instance

    --------+ Object_Spawner: [X] Is Key_Spawned

    ---------> Object_Spawner: Spawn Key_Gold on layer "a_objects" (image point 0, create hierarchy: False)

    ---------> Object_Spawner: Set Key_Spawned to True

    ---------> System: Wait for previous actions to complete

    ---------> scene_controller: Spawn Silver Key

    ----* scene_controller action 'Spawn Silver Key'

    --------+ System: Pick a random Object_Spawner instance

    --------+ Object_Spawner: [X] Is Key_Spawned

    ---------> Object_Spawner: Spawn Key_Silver on layer "a_objects" (image point 0, create hierarchy: False)

    ---------> Object_Spawner: Set Key_Spawned to True

    ---------> System: Wait for previous actions to complete

    ---------> scene_controller: Spawn Bronze Key

    ----* scene_controller action 'Spawn Bronze Key'

    --------+ System: Pick a random Object_Spawner instance

    --------+ Object_Spawner: [X] Is Key_Spawned

    ---------> Object_Spawner: Spawn Key_Bronze on layer "a_objects" (image point 0, create hierarchy: False)

    ---------> Object_Spawner: Set Key_Spawned to True

    ---------> System: Wait for previous actions to complete

    ---------> scene_controller: Spawn Coins

    ----* scene_controller action 'Spawn Coins'

    --------+ System: Pick all Object_Spawner

    --------+ Object_Spawner: [X] Is Key_Spawned

    ---------> Object_Spawner: Spawn obj_coin on layer "a_objects" (image point 0, create hierarchy: False)

    ---------> System: Wait for previous actions to complete

    ---------> scene_controller: Spawn Score

    ----* scene_controller action 'Spawn Score'

    --------+ System: Pick all Score_Spawner

    ---------> Score_Spawner: Spawn obj_coin on layer "a_objects" (image point 0, create hierarchy: False)

  • Can you post a screenshot of the event sheet? Or share your project file.

  • ** sorry ignore that 'spawn score' in the first 'on start of layout event, I forgot I added that when I was testing other solutions. **

  • I think the problem is that you are picking a random spawner first, and then checking if it has not spawned a key. If the first condition picked the spawner which has already spawned a key, the whole event won't run. You need to swap the order of these conditions in every event.

    Also, "Wait for previous action" should not be used like that - you need to remove them or replace with "Wait 0" if you want to wait to the end of the tick.

  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • I think the problem is that you are picking a random spawner first, and then checking if it has not spawned a key. If the first condition picked the spawner which has already spawned a key, the whole event won't run. You need to swap the order of these conditions in every event.

    Also, "Wait for previous action" should not be used like that - you need to remove them or replace with "Wait 0" if you want to wait to the end of the tick.

    Thanks very much for your response, I'll test it in the morning. Always happy to learn more about using construct! The wait for previous actions were something I was trying to see if it made a difference, thanks for clearing that up too.

  • > I think the problem is that you are picking a random spawner first, and then checking if it has not spawned a key. If the first condition picked the spawner which has already spawned a key, the whole event won't run. You need to swap the order of these conditions in every event.

    Worked perfectly, thanks for your help.

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