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
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.
Ok thankyou ;D.
I dont suppose you could explain to me how the changing of rooms works?
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?
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?
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.
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?
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.
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?
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;
o ok i didnt see that bit thankyou.
hopefully i wont have anymore problems.
youve been very helpful i thankyou KhrisMUC
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.
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.
ok ive searched thru the script like 20 times and i just cant find any missing }.
what should i do?
Use the match-brace feature of the script editor (ctrl-B near a bracket) to help check it.
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.
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
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.
Check out the tutorials on YouTube, they helped me a lot! :)
ok i will check them out.
KhrisMUC thats what i did.
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.");
}
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