Is this possible?

drew081886
Is it possible to script separate results for the same action performed on an object multiple times? In my game, I have a door that is locked and I'm trying to make it so that in order for the door to open, the player has to knock on the door three separate times. Ideally, the first two times would garner two different responses, while the third knock would result in the door being opened. Is something like this possible? Is there even a way for the game to keep track of how many times the player has interacted with an object?

XanMag
Well... Here are my two cents worth. Someone will tell you after I post this to create something more 'code friendly' than what I suggest, but here I am explaining things like a noob coder.

So... Here's what I would do and I have done it before with my two other games. I'd create three doors and keep two of them in a room that cannot be accessed during the game (I have a room that I call 'Item Warehouse' where I store all my miscellaneous stuff that I want to move in and out of rooms). So, three identical doors - two in 'item warehouse' and one in your current room. When you knock on door one, run a script that prints your desired message and also move that door to your 'item warehouse' AND move door number two to your current room (use move object option and move object to current room option). Make sure you name it the same thing as the original door in the 'Alias' box. Repeat. Knock on door. Print desired message. Move door two to 'item warehouse' and move door 3 to current room. Then, when you knock on the third door, print desired message, unlock the exit, and open the door to your next room.

Hope this helps. If you have questions about this method or anything else, let me know here or PM me.

Happy Gaming!

XanMag
*knock, knock, knock* "Penny."
*knock, knock, knock* "Penny."
*knock, knock, knock* "Penny."

The Pixie
This is the sort of thing I find myself doing a lot, especially with people as you want them to say different things if the player talks to them multiple time.

The more "code friendly" approach is to create an integer attribute on the door (Attributes tab); I always call it "state" and have it start at zero (which it will default to).

Then in your "knock on" script (i.e., the command or verb), you check the value of "state", and increment it. You could do that with a Switch command or a series of if else.
switch (this.state) {
case (0) {
msg ("You knock the first time.")
}
case (1) {
msg ("You knock again.")
}
case (2) {
msg ("Third time lucky, right?")
}
default {
msg ("Is there really any point in doing it again?")
}
}
this.state = this.state + 1

Using if/else might be easier if you do not like code view because of the way switch gets displayed.
if (this.state = 0) {
msg ("You knock the first time.")
}
else if (this.state = 1) {
msg ("You knock again.")
}
else if (this.state = 2) {
msg ("Third time lucky, right?")
}
else {
msg ("Is there really any point in doing it again?")
}
this.state = this.state + 1

Either way make sure you have a catchall at the end for when the player does it a hundred times.

By the way, I am using "this" as the object name. In case you do not know, "this" is a special word in Quest and refers to the object to which the script is attached, so the above will work with a verb, no matter what the object is called. If you are doing this as a command (and if you do not know what I am talking about, you probably are), just replace each "this" with the name of your door object (you can learn about verbs here if you are interested).

drew081886
The Pixie wrote:This is the sort of thing I find myself doing a lot, especially with people as you want them to say different things if the player talks to them multiple time.

The more "code friendly" approach is to create an integer attribute on the door (Attributes tab); I always call it "state" and have it start at zero (which it will default to).

Then in your "knock on" script (i.e., the command or verb), you check the value of "state", and increment it. You could do that with a Switch command or a series of if else.
switch (this.state) {
case (0) {
msg ("You knock the first time.")
}
case (1) {
msg ("You knock again.")
}
case (2) {
msg ("Third time lucky, right?")
}
default {
msg ("Is there really any point in doing it again?")
}
}
this.state = this.state + 1

Using if/else might be easier if you do not like code view because of the way switch gets displayed.
if (this.state = 0) {
msg ("You knock the first time.")
}
else if (this.state = 1) {
msg ("You knock again.")
}
else if (this.state = 2) {
msg ("Third time lucky, right?")
}
else {
msg ("Is there really any point in doing it again?")
}
this.state = this.state + 1

Either way make sure you have a catchall at the end for when the player does it a hundred times.

By the way, I am using "this" as the object name. In case you do not know, "this" is a special word in Quest and refers to the object to which the script is attached, so the above will work with a verb, no matter what the object is called. If you are doing this as a command (and if you do not know what I am talking about, you probably are), just replace each "this" with the name of your door object (you can learn about verbs here if you are interested).



That worked great, thanks. I used the if/else method. It really makes me want to learn the coding language. I would never have figured that out just using the GUI.

XanMag wrote:*knock, knock, knock* "Penny."
*knock, knock, knock* "Penny."
*knock, knock, knock* "Penny."


Ugh, thanks. I had *almost* forgotten that commercial existed. :roll:

This topic is now closed. Topics are closed after 60 days of inactivity.

Support

Forums