Adventure Game Studio

AGS Support => Beginners' Technical Questions => Topic started by: antomatic on Thu 25/12/2008 09:51:45

Title: changing rooms
Post by: antomatic on Thu 25/12/2008 09:51:45
Hi ive just recently stumbled upon AGS and im having a bit of trouble.
Im making a 2 room game mainly so i can get to grips with AGS.

The first room is a field with a cabin on it and a key out side the cabin the second room is the inside of the previously mentioned cabin. What i want to do is when my sprite uses the cabin door it displays "the door is locked" then i pick up the key and use the key on the door which then displays a message "the door is now unlocked", then the key dissapears from my inventory, i use the door once again and it takes me to the next room.

How would i go about doing this?

I have looked through many threads to try to find an answer and i have used the search function. I have gone through all the tutorials. I may have missed something after all i am only human.

Thankyou in advance
Title: Re: changing rooms
Post by: Khris on Thu 25/12/2008 13:44:25
bool door_unlocked;

function oDoor_Useinv() {
  if (player.ActiveInventory != iKey) player.Say("I can't use that on the door.");
  else {
    door_unlocked = true;
    player.LoseInventory(iKey);
    player.Say("I've unlocked the door.");
  }
}

function oDoor_Interact() {
  if (door_unlocked) player.ChangeRoom(2, x, y);
  else player.Say("The door is locked.");
}


Note that you can't just copy and paste this code; you must create the function bodies first via the door's events pane.
Title: Re: changing rooms
Post by: antomatic on Thu 25/12/2008 14:09:09
Ok thankyou ;D.

I dont suppose you could explain to me how the changing of rooms works?
Title: Re: changing rooms
Post by: Khris on Thu 25/12/2008 14:53:41
Just fill in the x and y coord of the spot the character's supposed to appear in room 2.
Or did you mean something else?
Title: Re: changing rooms
Post by: antomatic on Thu 25/12/2008 15:17:36
I thankyou for giving me the code but i would like to know how the code works and how to recreate it for other rooms.

Also in that code that you gave me does the door need to be an object?
Title: Re: changing rooms
Post by: Khris on Thu 25/12/2008 15:23:29
I'm still not sure what you're asking; you can look up the commands I've used in the help file.
Or are the 'if ... else' blocks unclear to you?

The door doesn't need to be an object, no, you can use a hotspot instead.
Title: Re: changing rooms
Post by: antomatic on Thu 25/12/2008 15:29:33
the 'if ... else' blocks i dont really understand so would you be able to just clear that up for me.

also in that code where it says iKey should i change it to oKey because thats what my key is called?
Title: Re: changing rooms
Post by: Khris on Thu 25/12/2008 16:20:24
oKey is the visible room object; iKey is the InventoryItem you gain after picking up the key (assuming you've set it up that way).
And iKey is what you can use on the door and thus lose afterwards.

if ... else:
http://www.adventuregamestudio.co.uk/manual/ifelsestatements.htm

It's really all in the manual, I suggest reading through it at least once, it's a very detailed and useful resource.
Title: Re: changing rooms
Post by: antomatic on Thu 25/12/2008 22:01:09
ok thankyou im reading through the maual but i have a problem with that script you gave me.

it gives me this error when i try to tun the game: " error (line 52): undefined sybol 'door_unlocked' " this is what i have in my script:

59     function hHotspot6_Interact()
60     {
61     if (door_unlocked) player.ChangeRoom(2, x, y);
62     else player.Say("The door is locked.");
63     }

whats wrong with it?
Title: Re: changing rooms
Post by: Khris on Thu 25/12/2008 22:17:28
door_unlocked is a variable I declared to keep track of the door being locked or not.
You have to declare it above the topmost function that uses it, using this line:
bool door_unlocked;
Title: Re: changing rooms
Post by: antomatic on Thu 25/12/2008 22:24:07
o ok i didnt see that bit thankyou.

hopefully i wont have anymore problems.

youve been very helpful i thankyou KhrisMUC
Title: Re: changing rooms
Post by: antomatic on Thu 25/12/2008 22:33:32
ok i think ima cry ive added bool door_unlocked; but now its giving me this error: error (line 61): nested functions not supported(you may have forgotten a closing brace)

this is the script:

61   function hHotspot6_Interact()
62   {
63   if (door_unlocked) player.ChangeRoom(2, x, y);
64   else player.Say("The door is locked.");
65   }

sorry about this im sure you have better things to do than help me so thankyou again.
Title: Re: changing rooms
Post by: Khris on Thu 25/12/2008 23:26:31
Look for a missing } somewhere above line 61.
You can see where the other brace is by moving the cursor next to one and pressing Ctrl-B.
Title: Re: changing rooms
Post by: antomatic on Fri 26/12/2008 10:25:54
ok ive searched thru the script like 20 times and i just cant find any missing }.

what should i do?
Title: Re: changing rooms
Post by: Gilbert on Fri 26/12/2008 12:41:03
Use the match-brace feature of the script editor (ctrl-B near a bracket) to help check it.
Title: Re: changing rooms
Post by: Khris on Fri 26/12/2008 14:19:03
Put a } in a new, empty line above current line 61.
If that still doesn't compile, indent your code properly and you should be able to find the missing one pretty quickly.
Title: Re: changing rooms
Post by: antomatic on Fri 26/12/2008 16:00:44
ok ive managed to sort hat ouyt but its saying: undefined sybol y

whats that all about?

EDIT: ive figured it out. but in the game its not letting me use the door
Title: Re: changing rooms
Post by: Khris on Fri 26/12/2008 17:38:12
Quote from: KhrisMUC on Thu 25/12/2008 13:44:25
Note that you can't just copy and paste this code; you must create the function bodies first via the door's events pane.
Title: Re: changing rooms
Post by: Nickydude on Fri 26/12/2008 18:09:29
Check out the tutorials on YouTube, they helped me a lot! :)
Title: Re: changing rooms
Post by: antomatic on Sat 27/12/2008 08:26:24
ok i will check them out.

KhrisMUC thats what i did.
Title: Re: changing rooms
Post by: Creator on Sat 27/12/2008 08:38:39
It's saying "Unidentified symbol 'y'" Because this is what you have:


function hHotspot6_Interact()
{
   if (door_unlocked) player.ChangeRoom(2, x, y); // The letters in the brackets of the change room function are the problem here.
   else player.Say("The door is locked.");
}


Change those to the coordinates you want the player to teleport to in room 2.

E.G:

function hHotspot6_Interact()
{
   if (door_unlocked) player.ChangeRoom(2, 160, 140);
   else player.Say("The door is locked.");
}
Title: Re: changing rooms
Post by: antomatic on Sun 28/12/2008 10:17:18
Quote from: antomatic on Fri 26/12/2008 16:00:44
ok ive managed to sort hat ouyt but its saying: undefined sybol y

whats that all about?

EDIT: ive figured it out. but in the game its not letting me use the door