How do I separate objects in conditions?

0 favourites
  • 10 posts
From the Asset Store
Welcome! I-Spy (Hidden objects) is an educational puzzle that is more than just seek-and-find activities.
  • When I pick up an item, I want to fill an empty slot. If I have 3 empty slots upon picking it up, just one of these must be filled instead of all 3.

    Since all the slots are same object and differentiate themselves only with a variable (1,2 or 3), I find it hard to check them all at the same time. If slot=1 is empty and slot=2 is empty just does not work since a slot is not both 1 and 2 at the same time. So I need to separate them in conditions and perhaps check them in steps.

    My mind want to structure it like this:

    if item picked up

    slot=1

    slot=empty (set to filled and stop checking)

    slot=2

    slot=empty

    slot=3

    slot=empty

    if item picked up

    slot=1

    slot=filled (check next)

    slot=2

    slot=empty (set to filled stop checking)

    slot=3

    slot=empty

    Does sub events solve this? If so, how should I structure it?

  • Yes you have the right idea. With a loop, so system for each(ordered), use slot and ordered by ID. Then off this a sub event if slot=empty : set item/fill etc, and also system Stop loop.

  • Glad you are here lionz! I have tried to put these principles in but I think I am missing something fundamental.

    Here is a screenshot of what I have constructed so far. The item on the ground is destroyed but no item appear in the bag when I test. NONE means empty, not NONE means filled. The global variable called "itemslot" is just the current selected one, which should swap a filled slot. This should happen for a selected slot if all slots are filled. Itemslots currently start from 3 and reach 5, since first slots are for specific gear.

    picallow.com/events-2

  • Take the triggering event of char out of the loop and run the loop one time like you are picking up an item, there's too much happening like the char overlapping the item while the loop is running, should be very simple like char picks up item then you trigger the loop and with the first sub event, where the loop is assigning the item to a slot only.

    To check if all slots are filled you can do if itemslot=none and run the normal pick up item loop only if itemslot.pickedcount > 0, then 'Else' means there are no empty slots you can run a different function, the swapping mechanism though this wasn't mentioned before.

    For swapping item it depends how you want to do it and needs to be designed first on when you would swap and how and which slots are picked.

  • The swapping already works. This was tested before the system got more complex.

    However I will take your advice and make a check when something is picked up and run the loop afterwards. I will also try "else" to check if all slots are filled.

    Thanks!

  • Could you just have 3 global variables

    On pickup.

    Check slot 1.

    If global variable=0 then set global variable to uid of object picked up. Else check pickup2. Else check pickup3.

    The 3 slots will have uids set to them. And you can choose any object base on its uid

    On drop, just set the slot global variable to 0 again

  • The swapping already works. This was tested before the system got more complex.

    However I will take your advice and make a check when something is picked up and run the loop afterwards. I will also try "else" to check if all slots are filled.

    Thanks!

    Oh okay, what isn't working?

  • Could you just have 3 global variables

    On pickup.

    Check slot 1.

    If global variable=0 then set global variable to uid of object picked up. Else check pickup2. Else check pickup3.

    The 3 slots will have uids set to them. And you can choose any object base on its uid

    On drop, just set the slot global variable to 0 again

    That sure is smart but I currently use instance variables for objects. Will try the "else" method later but must sleep first. Thanks for the simple idea :)

  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • > The swapping already works. This was tested before the system got more complex.

    >

    > However I will take your advice and make a check when something is picked up and run the loop afterwards. I will also try "else" to check if all slots are filled.

    >

    > Thanks!

    Oh okay, what isn't working?

    I have not tried it yet since I must take a break and sleep. I am back at it tomorrow :)

  • > The swapping already works. This was tested before the system got more complex.

    >

    > However I will take your advice and make a check when something is picked up and run the loop afterwards. I will also try "else" to check if all slots are filled.

    >

    > Thanks!

    Oh okay, what isn't working?

    I figured out another way to solve it. If player overlaps an item and picks it up the item is destroyed, preventing actions further down the code. So I just placed each event in order in the sheet starting with if itemslot=3 then itemslot=4 etc.

    Like this:

    If player overlaps item

    Picks up

    itemslot=3

    itemslot=empty

    -set itemslot filled

    -destroy item

    If player overlaps item

    Picks up

    itemslot=4

    itemslot=empty

    -set itemslot filled

    -destroy item

    If player overlaps item

    Picks up

    itemslot=5

    itemslot=empty

    -set itemslot filled

    -destroy item

    Since the item is destroyed when one of these are true it simply stops the next event since the player is not overlapping item anymore.

    After these events I replaced the =empty with =filled and repeated the events but adding the replace actions.

    This works nicely since I will not have more than a maximum of 6 itemslots, so code won't be too long. Just thought I'd let you know how I solved it.

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