Unlocking Doors through different layouts

0 favourites
  • 13 posts
From the Asset Store
Adjusting the game screen for different resolutions (Letterbox scale)
  • Hello,

    Might be a beginner question..

    I use several Layouts.

    They are sometimes connected with doors (1 layout can have from 1 to 4 doors - leading to 1-4 differents layouts).

    The player can also go back to any previous layouts if he wants to.

    If a door is unlocked/open from the start, no problem as it will always be open.

    But if it's locked and the player has to unlock it then I got a problem.

    Because if the player unlocks it, proceed to the next layout, and suddenly decide to go back to the previous layout, that door is locked again.

    How do I keep that door open/unlocked when reloading its layout ?

    I'm sure it's with the help of Global variable....but I cant find a proper solution..

    Any help would be appreciated, thanks !

    Edit: also all the layouts share 1 single event sheet, so I would like to keep it like that if possible.

  • Extremely in depth Tutorial

    Simle answer. Store in global variables or webstorage etc.

    So door1 = 0 (locked)

    player unlocks

    door1 = 1 (unlocked)

    If door1 = 1

    do something etc etc

  • Thanks Dutoit, that tutorial is nice but it uses arrays for storing the doors states...and I dont use arrays :/

    Im still trying to figure out how to store the doors differents states using global variables...like you said.

    Lets say the Level_1 Door is locked.

    There is 1 key in this Level.

    Once the key has been picked up, the door is unlocked

    Level_2 is now available (and you can go back to level_1 (now unlocked) from there.

    The lock mechanics I'm using is as follow:

    Door boolean = "locked" (=solid)

    Player pickup key -> Door: Set boolean to "unlocked" "(=not solid)

    But how do I store this in a global variable ? that's where my brain is stuck...

    I believe I need a global variable for each doors ?

    So something like

    Door_1= 0 (locked)

    Door_1= 1 (unlocked)

    And so on for door_2, 3, etc

    But how do I link theses global to the appropriate door/layout ? (using a single event sheet and a single door object...which is/will be instanced)

  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • Think of it like that.

    System> compare variable 'Door_1' > if = 0> door1.solid = true(door locked)

    else door1.solid = false( door unlocked).

    Just do that for all your doors. Have you tried it? What's exactly your problem, isn't it working or you are having trouble making the logic?

  • It's hard to explain,

    Basically I have 1 object (the door) and 1 global variable to store the lock/unlock state through all layouts.

    But I dont know how to link the object (door) to the global variable without having to create multiple objects/doors instead of using instances.

    I have found a solution...which is to create an additional event_sheet for each layout that has a key/door mechanism in it...that's certainly not the best solution...but it works so far...so...

    But Still if anyone got a better solution (and is able to understand my poor explanation

  • Thanks Dutoit, that tutorial is nice but it uses arrays for storing the doors states...and I dont use arrays :/

    I suggest you start using arrays or at least dictionary.

    Game have lots and lots and lots of data, and you can't store everything into variables.

    Think 100's of variables and the nightmare it becomes.

    Anyways, caiorosisca gave great explanation.

    Edit: You don't have to create new event sheet each layout. Create 1 event sheet. And include it into each layout.

  • Edit: You don't have to create new event sheet each layout. Create 1 event sheet. And include it into each layout.

    Yeah but then my problem would be the same.....I dont know how to manage multiple layout/doors linked to global variables.

    Here's my separated event_sheet (for the level_1) if you want to take a look:

    This is how I managed to apply this mechanism to multiples doors/layout...but as I said, not the best solution I guess.

    I think I know what caiorosisca means, but what I'm asking, is how to store the doors state in beetween layouts...

    I'm gonna take a look at the dictionary, hopefully I will get something better from it

  • If you are looking for the a better way, global variables really isn't your answer, as DUTOIT said, I would go with a dictionary.

    It isn't hard to understand at all, even if you never used it. A dictionary is a list with 2 colluns, imagine something like that

    key value

    "key1" 2

    "banana" 5

    "green" 3

    basically you can store anything on it, and if you check the value for banana for example, it will be 5.

    Now back to your door, you can use only one instance of the door, create an instance variable on it ( I would go for something like "doorNumber"), so each door will have it's number.

    Your dictionary would look like this:

    "door1" 1

    "door2" 0

    "door3" 0

    The key part(left one) you would acess using "door"&Door.doorNumber. // Door would be the actual object, 0 means locked, 1 means unlocked (you can also use strings if you like, "locked"/"unlocked").

    To check if the doors are locked or not, you can use:

    Pick all "Door"> Dictionary, compare key> "door"&doorNumber, if equals 1(or "unlocked") set solid to false.

    Let me know if I can help with something else(please tag me)

  • That sounds very good, thanks for the explanation caiorosisca

    I'll definately give this a try.

  • Well well, looks like I have some troubles to achieve what I want with the dictionary...

    As it's hard to explain for me, here is a little screenshot of my event_sheet:

    I'm not used to use "pick all", so it might come from that...Or the fact that I use both 2 objects's instance variables (the key, and the door) to call the dictionary's key "door_1" ?

    (the door has a boolean "open" true/false wich is not in this event_sheet....but which is working correctly (or at least it was so I'm pretty sure it's my dictionary's event that has a problem)

    Do you see what I'm doing wrong ?

  • I can't see what's wrong and I'm on mac right now :/.. To be honest, I too struggle with the events in C2. I'm a programmer but I'm also new to Construct so I'm not used to the pick stuff and the flow of events yet.

    What I can think of without having construct to try, make your "Pick all obj_door" and subevents a subevent of the hero_base on collision event.

    Also there's no need to verify if the key value is 0, if your door already start as locked.

  • I've made it

    for thoses wo might be interrested here is how I've done it:

    Seems to be working so far so i'm happy

    Thanks for trying to help caiorosisca

  • You should consider saving data to webstorage - so that player doesn't loose his keys when he leaves game. Set save progress up early, else it is going to be a nightmare later

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