How do I use booleans with families?

0 favourites
  • 9 posts
  • Hi all,

    I am encountering a weird issue with my "pickUp item" function. Basically all my items are in a family called "items" and this family has an instance variable which is a boolean called "stackable". If the item has stackable set to true, then I want it to go down a specific path in my function so it may stack with any of the same items that are already present in the players inventory. If this boolean is false, I want it to go down a different path in the function and take up a slot of its own.

    So how I've done it is when the function is called the first thing it does is evaluate this boolean and based on this it should send the item down one path or the other...but this isn't happening.

    No matter what the boolean is set to, the item goes down both paths. It seems that the function is ignoring this check entirely.

    Here is a screenshot of how the function is set up.

    I have no idea why it would be ignoring this boolean check. Any suggestions of things to try? I've been trying to figure this out for a while and really need it to work.

    Thanks in advance for your help!

  • You need to pick the right item instance inside the function. Otherwise it will process all your items. The most common way to do this is to pass Items.UID in function parameter, and use "Items pick by unique ID" inside the function. After that, in a sub-event you can check if this item is stackable.

  • Hey dop2000 Thanks as always for your help!

    I tried adding a parameter and passing in the items UID by passing in items.UID into a paramaeter called "UID". I then make the first step "items, pick by UID", before sorting by the stackable boolean. Unfortunately this doesn't seem to work either.

    For some reason it is treating them all as non-stackable now, even when I have the boolean set to true for some of the items.

    Here is a screenshot of my updated config.

    Any ideas about what might be going wrong here?

    Thanks in advance for your help!

  • The function looks fine. The mistake may be inside these events, or somewhere else. Have you tried running in Debug Mode?

  • Hey dop2000 I did try running in debug mode and the boolean seems to be set correctly. For testing purposes I have my "stone" items set up to be stackable, and my "wood" items to not be stackable.

    Here is a link to my project file if you feel like taking a look:

    I appreciate all your help!

  • It works if you pick item by UID. You can open browser console and check the messages:

  • Hey dop2000 thanks for looking into this!

    I see what I was doing wrong was passing items.uid instead of stone.uid so this does work for specific instances but I wonder is there a way to do this with families?

    For example when my character collides with anything from the "crop" family, it doesn't know specifically which crop it is picking up until it sorts it into the inventory so I don't say carrot.uid, artichoke.uid, I can only say crops.uid but I just tried this and it doesn't seem to work.

    Any thoughts on this issue? Or does this method just not work with families?

  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • It will work for families, but you need to pass the same object/family UID you use in "On collision" event. If you have "On collision with stone", you need to pass stone.UID. If you have "On collision with RocksFamily", pass RockFamily.UID

  • dop2000 Oh that does work! I don't know why I thought it didn't yesterday...must have done something else incorrectly.

    Thanks again for all your help! Saved the day again!

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