How do I select just one instance of an object at a time?

0 favourites
  • 5 posts
From the Asset Store
Hand-painted tiles, objects, animated objects, and background to build a colorful Mayan civilization environment.
  • The player can pick up items on ground. When picking up an item, it is destroyed and an empty item slot, picked from the left gets the name of the item. However, if 2 items are overlapping the player, both gets destroyed but only 1 item slot is used.

    How can I make sure only 1 item is picked up at a time? I have tried using pick nth instance and pick random instance with sub events but it does not seem to make a difference. The player is a single object and the items belong to a family called "items".

    My current logic:

    player is overlapping items

    interact=1

    itemslot1=empty

    itemslot2=empty

    itemslot3=empty

    trigger once

    -sub event-

    pick nth instance=0

    -sub event action-

    set itemslot1.name name=items

    destroy items

    As said it works fine as long as just 1 item is picked up at a time.

  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • I don't really trust the overlapping condition with trigger once, try instead player on collision with items and a trigger once not required. If nth instance doesn't work try 'pick top instance'.

    If it still doesn't work please then share a screenshot of the events as I want to see the structure and what objects were used etc

  • I will not use on collision since the player must press a button to pick up an item. Anyway, here is a screenshot. Thanks in advance!

  • Key press works too but wasn't mentioned. Pick items instance 0 won't do anything because the overlap check was done with item. The object type matters here so you can't pick between item and the family items, it should be just the one object then it will work. If you replace the one reference to family with 'item' then it will work, however if you plan to have multiple different objects you can pick up then I would start using the family now and replace references to item with the family items and move the item variables to family instance variables.

  • Thanks! I missed the detail that I had accidentally used the object and then the family. Will try changing that and come back if the problem persists.

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