How do I get collected items to spawn?

0 favourites
  • 9 posts
From the Asset Store
Pick Up Items Sound effects for your game, Take them for a ride right now and you will worry no more.
  • I have a setup where a character collects items, which are then 'stored' in a box in another layout. How do I get a random collected item instance to spawn every time the box sprite is clicked or touched?

  • What is the logic that you've used for collecting and storing items?

  • Hey there, do you have a dictionary or an array that store the information that the item have been collected?

    Edit : lionz outspeeded me on this lol

  • Hi Tomycase and lionz,

    I originally planned to use an array but haven't been able to get it to work. Any advice on how to collect and store items using the array would be really helpful.

  • That's kind of an entirely different question because you said you've already set it up. You could check the manual on arrays, they are simple to use but difficult to explain everything in a forum post. There are also existing posts on inventories using arrays and tutorials available.

  • Hi,

    Sorry about that. I've recently made a little progress by making a few changes to this tutorial: construct.net/en/tutorials/creating-inventory-arrays-475

    I'm now able to get items stored in the array to spawn when the box object is touched, but can only get all stored items to spawn at once. I'm currently using "for each X element". What should I change this to to make only one object spawn per touch?

  • Instead of using For each element, which will pick each element of the array as it says, you should only pick a random one

  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • Thanks, Tomycase.

    I've changed it to "Pick Random Instance" and it works, but now each item has the same animation when created. The "Set Animation" action seems to have stopped working.

  • When you say it works what do you mean exactly because that condition is not good. You'll probably find the item names are wrong and all the first value of the array? Technically the actions are correct though. With that condition you are saying to pick a random array object not a random value inside the array.

    To fix this, drop the condition. At the top of the actions set a local variable to the value round(random(0,inventory.width)) to choose a random row of the array. This variable will then be the item you need, you can use the variable in the other actions such as ItemName becomes inventory.at(variable).

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