Hello again, I have an exit that is locked, so what commanded to I have to use to make my key unlock it? Or is there a way I can trigger it to unlock when a certain item is picked up
In any script, you can unlock an exit by doing something like:
name_of_exit.locked = false
Note that you have to give an exit a name before that will work.
It is also possible to give the exit an "unlock" verb; but "lock" and "unlock" are designed for containers, it requires a little extra work.
First, you'd need to make the unlock verb work on exits as well as objects, by giving it script attribute named changecommandscope containing the script:
foreach (exit, ScopeExits()) {
list add (items, exit)
}
Then you'd want to give the exit attributes like autounlock, keycount, key, lockmessage, and so on. I'm not sure, but I think that making the exit inherit container_lockable might add the tab to edit these values in the GUI.
Not sure if this would be that helpful but I pulled this from my template and tutorial "game". Ask if you have questions! And I ASSUME you are using the downloaded version.
So, I want to have exit unlock once the player has a book in their inventory. I have the script for the exit that says "If a player carries object" then the exit is to unlock but nothing happens.
On the book, try ticking script when object is picked up. Add to that script:
So, I want to have exit unlock once the player has a book in their inventory. I have the script for the exit that says "If a player carries object" then the exit is to unlock but nothing happens.
The script on an exit runs only if the exit is unlocked, instead of going through it.
So you'd want to make the exit not locked, but give it a script like:
if (Got (book)) {
MovePlayer (this.to)
}
else {
msg ("You push at the door, but it doesn't open")
}
(changing book to the name of the book object)
One last thing, all of it works, but the player can't get to the next room. I type in "go outside," and the message plays about leaving the first room, but the player is still in the first room.
Hm. A simple solution would be to add a script:
when they type "go outside"
One last thing, all of it works, but the player can't get to the next room. I type in "go outside," and the message plays about leaving the first room, but the player is still in the first room.
Did you use the method I suggested, or the method XanMag suggested?
If mine, did you remember to include the MovePlayer line?
If you're still having problems, it might be worth including the script that you're using (code view is good for copying and pasting excerpts here, even if you prefer to edit in the GUI); or a link to the game so we can see the problem.
I do have one more question. is there a way to make it where the exit can only be unlocked when you have three certain objects in your inventory?
The following is an example from my tutorial that I use. I used puzzle pieces and a jigsaw puzzle. Use what makes sense to you.
explain room
This is a frequent problem I see on the forums and one that I struggled with for the longest time. Once I figured this out, it is most likely the most helpful bit of coding I have learned. It really opens up gaming options! So, I will try to make this simple.
You will use something like this whenever you want multiple things to get accomplished before it triggers a new event or singular accomplishment. Want to have multiple keys used to open a door? Or, multiple pieces of a password collected before punching in a code? You want to wear multiple different pieces of clothing before you can sneak in to a top secret lab?? This is your answer.
I know this is long winded and I hope it makes sense. You just have to change the name of your objects to whatever you named them and change the name of your attribute to whatever you named it.
Ask if you have questions!
is there a way to make it where the exit can only be unlocked when you have three certain objects in your inventory?
You could modify the existing script:
if (Got (bell) and Got (book) and Got (candle)) {
msg ("You wave three items at the door and it opens!")
MovePlayer (this.to)
}
else {
msg ("You push at the door, but it doesn't open")
}
Or if you want to make the messages give more of a clue:
if (not Got (bell)) {
msg ("You don't feel comfortable leaving your bell behind.")
}
else if (not Got (book)) {
msg ("You haven't got anything to read yet.")
}
else if (not Got (candle)) {
msg ("It's too dark to go out without a light source.")
}
else {
msg ("You wave three items at the door and it opens!")
MovePlayer (this.to)
}
If you want the exit to 'unlock' so that the player doesn't need the items once they've been through once, you can add the line:
this.script = null
before the MovePlayer line; so that it removes the script and turns the exit into a normal one.
mrangel, how do I modify the existing script? is it expression? or is it the code?