Posted By: mschoenhals
Doors and Keys - 08/26/15 16:15
Hi all,
I'm trying to create locking doors with keys. I can get a rotating door working just fine; I can create the lock and even the variable for unlocking but I can't get the key action to work correctly. I'm uncertain on how to switch my variable during the game. If I switch it in code, it works. Below is the variables, locking function and the door function. Can someone suggest a key action that would work with my code?
I'm trying to create locking doors with keys. I can get a rotating door working just fine; I can create the lock and even the variable for unlocking but I can't get the key action to work correctly. I'm uncertain on how to switch my variable during the game. If I switch it in code, it works. Below is the variables, locking function and the door function. Can someone suggest a key action that would work with my code?
Code:
var have_key1 = false; //beginning of game you don't have the key var have_key2 = false; STRING* got_key_wav = "gotkey.wav"; //sets the file name for getting a key STRING* door_opens_wav = "dooropens.wav"; //sets the file name for opening the door ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////// function lock_check(){ if(//////////////////////////////////// (my.skill1 == 0) || //if the door is set to 0, it has no lock. The || means OR. (my.skill1 == 1 && have_key1) || //you have key one or.... (my.skill1 == 2 && have_key2) //my.skill1 is defined in the first skill of the key model. ){return (false);} //you either have the key or there is no lock else{ return (true); } } action door(){ //this will appear as the behavior in WED set(me, POLYGON | SHADOW); //polygon sets it for collision with player. var door_swing_speed = 5; //variable speed for door swinging var closed_pan = my.pan; //variable for closed door var OPEN_OR_CLOSED = 0; // -- 0 is closed if(is(my,FLAG1)) {OPEN_OR_CLOSED = 1;my.pan+=90;closed_pan = my.pan-90;} //if you check flag1 in WED, 1 is Open. VECTOR door_handle; //vector spot on the model, that's where the player needs to be closest to activate the door. vec_for_vertex(door_handle, me, 8); //check what vertex to use for the door handle. This is defined in MED while(1){wait(1); if(lock_check() == false){ //lock check is defined above. If it returns false, you can open the door. if(vec_dist(door_handle.x, player.x) < 100 && key_enter == 1 && my.pan == closed_pan){ //this for a closed door being opened. set(me, PASSABLE); while(my.pan < closed_pan+90){wait(1);my.pan+=door_swing_speed;} SND_CREATE_STATIC(door_opens, door_opens_wav); // play the "door opens" sound snd_play(door_opens, 100, 0); reset(me, PASSABLE); //when it is opening, it won't get hung up on things while(key_enter){wait(1);} } if(vec_dist(door_handle.x, player.x) < 100 && key_enter == 1 && my.pan == closed_pan+90){ //this for an open door being closed. set(me, PASSABLE); while(my.pan > closed_pan){wait(1);my.pan-=door_swing_speed;} SND_CREATE_STATIC(door_opens, door_opens_wav); // play the "door opens" sound snd_play(door_opens, 100, 0); reset(me, PASSABLE); while(key_enter){wait(1);} } } } }