How do containers work?

0 favourites
  • 11 posts
  • Hey everybody,

    Yet again there is something bothering me. This time it’s doors. I included a sample capx so everybody can check what I try to describe here :)

    How everything will work:

    Each door has boolean variable isLocket. This needs to be false for player to be able to open a door. Door_Opener sprite object is added as a container. This will serve as a trigger. When player overlaps with this object and Door is not locket (boolean variable isLocket = false), correct door will open. There is also a condition that a proper animation of the door is playing before door can be opened. Then, when player isn’t overlapping Door_Opener, correct door will close.

    Here is couple of screenshots to give you a perspective.

    Picture1:

    h*t*t*p*s://dl.dropboxusercontent.com/u/43020976/Doors%20and%20container/Door%20screenshots/working%20both%20opened.png

    Picture2:

    h*t*t*p*s://dl.dropboxusercontent.com/u/43020976/Doors%20and%20container/Door%20screenshots/working%20one%20opened.png

    Problem is that the other door's won’t close if player is overlapping with multiple Door_Opener’s.

    Picture3:

    h*t*t*p*s://dl.dropboxusercontent.com/u/43020976/Doors%20and%20container/Door%20screenshots/not%20working%20both%20opened.png

    I did found out how to correct this. Just needed to add “for each: Door” -condition and then everything will work properly. Sample capx contains 2 door groups. Enable/disable to switch between working and not working events.

    My question is though: why I need to add that “for each” condition? I though that boolean variable (isLocket) will pick each object separately (and also Door_Opener's because they are containers of Door ohject's).

    Or clearly there is something I don’t know about containers and how they behave :)

    Sample capx: h*t*t*p*s://dl.dropboxusercontent.com/u/43020976/Doors%20and%20container/Open_door_with_container_r233.capx

    -M-

  • Problem is that the other door's won’t close if player is overlapping with multiple Door_Opener’s.

    It does work, you just have the initial bool set to true on that left door.

    My question is though: why I need to add that “for each” condition? I though that boolean variable (isLocket) will pick each object separately (and also Door_Opener's because they are containers of Door ohject's).

    You don't need a for each. If you just have door is boolean set, then it will just check each door as if it was a for each.

  • I cant access your file(s), or i am to dumb to figure out the link.

    'Boolean variable (isLocket)' will pick ALL 'Door' s who's Boolean is set. So, you end up with a list of picked objects (with theire individual index (IID). I suppose most 'Door' s are just locked.

    Now you ask your self: do i want to apply the actions to all of them

    In the 'yes i do' case, there is no 'for each' needed.

    In the other case you will have to reach out to each object one by one. Usually there will be a 'follow up' condition to see if each individual object meets some conditions. In your case 'when player overlaps this object'.

    In general, this 'follow up condition' starts picking from the previous picked list (all those with the boolean set) and filters that previous picked list to meet the condition. (the result can be again a new list, depends on the condition)

    When using a 'for each' this means each object, one by one. (the new list contains 1 object)

  • 99Instances2Go , just remove those *** between h*t*t*p*s and you are good to go

  • >

    > Problem is that the other door's won’t close if player is overlapping with multiple Door_Opener’s.

    >

    It does work, you just have the initial bool set to true on that left door.

    But player character isn't overlapping left door's Door_Opener container? Like in even sheets are conditions: Door.isLocket = false and Hitbox is overlapping Door_Opener and animation "closed" is playing>>> open door else Hitbox is NOT overlapping Door_Opener and animation "opened" is playing >>> close door.

    So why that other Door_Opener is also picked? I understand what you said about boolean variable but that Door_Opener is a container of that left door so it should not be picket because player is not overlapping it. Clearly I'm missing something here :/

    -M-

  • You said door too many times so it's too confusing to me now. You said the other doors will not close if the player is overlapping multiple openers. What do you want to happen?

  • , Sorry if I confused you. That was not intentional.

    Each sprite object called "Door" has another sprite object called "Door_Opener" added as a container. This "Door_Opener" will serve as a trigger to open correct "Door".

    What I want to happen:

    1) Sprite object "Door" boolen variable "isLocket" = false,

    2) when player is overlapping sprite object "Door_Opener",

    3) check which "Door" sprite object is container of this "Door_Opener" object and pick correct "Door",

    4) Open that "Door".

    Quote from Scirra manual: "If a condition picks one object in a container, every other associated object in its container is also picked." and "Adding them both to a container then allows events to treat both objects as if they were one, because they are always picked together."

    My question is: why boolean variable "isLocket" is not enough to filter out correct "Door"? I need for each: "Door" -loop to do that. Because "Door_Opener" is added as a container to "Door", I thought boolean variable "isLocket" will pick each individual "Door" AND "Door_Opener" sprite objects (because of the container -thingy).

    -M-

  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • I just deleted all of your logic and put in one line : Player is overlapping door_opener > set door animation "open", it picks the door that is in the container with the door opener you are overlapping. If you overlap two door_openers then it opens the doors in both. Seems to work fine.

  • I just deleted all of your logic and put in one line : Player is overlapping door_opener > set door animation "open", it picks the door that is in the container with the door opener you are overlapping. If you overlap two door_openers then it opens the doors in both. Seems to work fine.

    , yes, opening door indeed works. That isn't the problem. Problem is closing. Other "Door" won’t close if player is overlapping with "Door_Opener AND there is also another "Door_Opener" overlapping that same "Door_Opener".

    Problem:

    h*t*t*p*s://dl.dropboxusercontent.com/u/43020976/Doors%20and%20container/Door%20screenshots/not%20working%20both%20opened.png

    Like I wrote in my initial post, I know how to fix this, I just want know why boolean variable "isLocket" isn't enough to pick each individual "Door" and "Door_Opener" object. I want to learn this because then I have a knowledge (or at least a hunch) of what might cause the problem or if I ran into a similar situation in future projects.

    -M-

  • Oh right I see your problem now, damn that was confusing. You will need to use a for each so it checks individual containers separately, without using that its just true if any door is in use, and by that I mean anything in the container, so if any door_opener is overlapped it makes it true as well.

  • Conclusion: boolean variable isn't applied to containers. That is good to know.

    , thank you very much for your answers AND patience. I Just read my previous posts and I realised that the way I described everything wasn't very clear. Sorry for confusion I caused to you.

    I will improve the way I describe things in the future

    -M-

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