Help with scripting. (Locked door)

Started by qcenaman, Mon 01/11/2010 23:04:31

Previous topic - Next topic

qcenaman

Hi, everyone, i started experimenting with AGS a few days ago, i have been following some videos on youtube, but those videos do not adress some of my problems.

I made a few rooms just as a test so i can learn the program, and in one of those rooms, i made a door wich is locked, so you need a key you can find in another room.

Everything works fine, i get the key open the door and enter the room.

But i do not know how to make that door always open after the key has been used.

I thought of teleporting the player to another copy of the room where the door is always open, but i think this is no real solution. There must be a way to do this with scripting.

Can anyone help me on this?

Thanks is advance.

Matti

Use a variable like this:

Code: ags

bool doorlock=true

// interact with door:
if (doorlock) cEgo.Say ("It's closed.");
else cEgo.ChangeRoom(x);

// use key on door:
doorlock=false;

qcenaman

Thank you for your answer, but please remember I'm a "noob" on this program.

What i did was something i saw on a video and this is what i used:



function hHotspot2_UseInv()
{
if (cEgo.ActiveInventory == iKey)
player.ChangeRoom(3, 477, 477);
}


So how would i integrate your code with this?

Matti

#3
Code: ags

bool doorlock=true; // put this at the beginning of the room script

function hHotspot2_UseInv() // Player uses key on door
{
if (cEgo.ActiveInventory == iKey){
  if (doorlock) {
    cEgo.Say ("I unlocked the door");
    doorlock=false;
  }
  else cEgo.Say ("The door is already unlocked.");
}

function hHotspot2_Interact() // Player interacts with door
{
if (doorlock) cEgo.Say ("It's locked.");
else player.ChangeRoom(3, 477, 477);
}


Now the player can't open the door unless he uses the key and after he used the key the door stays open and he goes through by interacting with the door.

qcenaman

ok i put what you said but now i get a error, it says:

Error (line 13): Nested functions not supported (you may have forgotten a closing brace)


This is what i have there:

// room script file
bool doorlock=true;

function hHotspot2_UseInv()
{
if (cEgo.ActiveInventory == iKey){
  if (doorlock) {
    cEgo.Say ("I unlocked the door");
    doorlock=false;
  }
  else cEgo.Say ("The door is already unlocked.");
}
function hHotspot2_Interact()------------------------------------------>here is line 13
{
if (doorlock) cEgo.Say ("It's locked.");
else player.ChangeRoom(3, 477, 477);
}




I tried to put a } before that line and it will enter game, but it doesn´t say it´s locked when interacting without key, and after interacting with key, it wont teleport to the other room, what do you think it´s wrong here?

Btw thank you for your time.

Matti

Quote from: qcenaman on Tue 02/11/2010 00:02:37
I tried to put a } before that line and it will enter game

Yes, sorry, I forgot one brace.

Quote
it doesn´t say it´s locked when interacting without key

Hm, I don't see a mistake here..

Quote
and after interacting with key, it wont teleport to the other room, what do you think it´s wrong here?

In my code the player has to interact the door again after using the key. This should do it:

Code: ags

  if (doorlock) {
    cEgo.Say ("I unlocked the door");
    doorlock=false;
    player.ChangeRoom(3, 477, 477);
  }


Quote
Btw thank you for your time.

No problem, despite this being basic stuff that could be looked up using the search function ;)
But now I gotta go to bed..

Oh and please use the code-tags. Just quote my post to see how it's done.

qcenaman

It was my fault too, besides that brace i forgot to add something to the events, its working fine now, everything is ok.

Thank you very very much for your time.

And about the search, this scripting thing has so many words and functions that i really don´t know what to search for!!

Anyway, thank you again for your time, you really helped me a lot.

Khris

You don't have to search the forums for script commands, just search for something like "locked door".
I did this and the 6th or so result is this thread which applies exactly to your problem:
http://www.adventuregamestudio.co.uk/yabb/index.php?topic=38849.0

qcenaman

Thank you too khris, ill try to do that from now on.

SMF spam blocked by CleanTalk