Creating an exit by action

Enju
13 Feb 2016, 15:28
I tried to find something similar in the tutorial/documentation but can't get behind it.
Basically what I am trying to do is making an iron door that creates an exit when you "kick it in", I tried to make it so that if you "Push" the door you get the question/reply that the door won't be opened from simply pushing, but you could try to kick it so it might move.
Now, I searched for an hour, how can I create a "Question"(Yes/No) and then run a message and a script to unlock the door?

XanMag
13 Feb 2016, 15:41
Enju wrote: how can I create a "Question"(Yes/No) and then run a message and a script to unlock the door?


You want to produce a yes/no question in response to trying to push the door open? Like... "You try to push the door open but you realize that won't do. Would you like to try and kick the door down?"

And if the player responds with "yes", the door will unlock?

Before I offer the solution, I want to make sure I have the scenario correct. So, is that what you want?

Cylius_Optimi
14 Feb 2016, 01:23
You could achieve your desired effect like so:
Exit (direction):
Name: door
Locked: True
Run a Script (instead of moving the player automatically):
if (this.locked) {
msg ("You try to push the door open but you realize that won't do. Would you like to try and {command:kick the door down}?")
} else {
MoveObject (game.pov, this.to)
}

Local room command (Kick in Door):
Pattern: "kick door; kick the door; kick in door; kick in the door; kick the door in; kick down door; kick down the door; kick the door down"

Script:
if (this.locked) {
msg ("You kick the door with everything you've got. It comes off of its hinges with a snap and a spray of splinters.")
this.locked = false
} else {
msg ("You've already kicked down the door.")
}


How does this work? First, you have a named exit - it having a name is crucial; the name itself doesn't matter, I just picked 'door'. Without a name, you can't unlock it. Second, you have a command inside the room with the exit; if it's at the top, with the rest of the commands, the player could just "kick down the door" from anywhere - even across the world!

When the exit is locked, it won't let you go through; instead, it'll ask if you want to kick the door down. The {command} bit tells the parser to insert a clickable link; if the player clicks the link, it will run the command you made, and unlock the door.

Hope this helped.

Enju
14 Feb 2016, 10:12
XanMag wrote:You want to produce a yes/no question in response to trying to push the door open? Like... "You try to push the door open but you realize that won't do. Would you like to try and kick the door down?"

And if the player responds with "yes", the door will unlock?

Before I offer the solution, I want to make sure I have the scenario correct. So, is that what you want?

Yes, that's what I want, can't get around how to do it, there's more to it than simply opening the door, but creating that yes no question is what I really can't get behind

HegemonKhan
14 Feb 2016, 13:38
there's some different ways of implementing what you want, but here's the basic syntax of your two questions:

(yes, this is as code, the other posters can help you with implementing it however you want through using the GUI~Editor, if you don't know how to code)

--------------------

Creating an Exit via Scripting:

http://docs.textadventures.co.uk/quest/ ... _exit.html

example:

create exit ("exit1A", "doorway", room1, room2, "northdirection")
create exit ("exit1B", "doorway", room2, room1, "southdirection")

---------------------

the 'ask' Script~Function (not the 'ask' Verb/Command, that's something else entirely):

http://docs.textadventures.co.uk/quest/scripts/ask.html

'ask' is the popup window menu version of it
'Ask' is the in-line (in the big text box area on the left side) version of it

(note that it is ONLY a 'yes/no' dualism/binary option choice, so you need to write your question message reflecting this aspect, thus, if you want more option choices than the limitation of dualism/binary of 'yes/no' option choices, then don't use this 'ask' Script~Function)

an example of its syntax:

ask ("Are you a male?") {
if (result) {
msg ("Ah, so you are a male.")
} else {
msg ("Oh, you're not a male.")
}
}


the 'ask' Script~Function, automatically (hidden from you), sets (is assigned to 'result' Variable):

result = true
~OR~
result = false

if you chose 'yes', it converts that to the boolean flag keyword: true, which is as seen above, is assigned to the Variable: result, as shown above
if you chose 'no', it converts that to the boolean flag keyword: false, which is as seen above, is assigned to the Variable: result, as shown above

so...

if (result) -> is the short-hand syntax for: if (result = true) -> which is conceptually:

if (true = true) -> TRUE -> run the nested scripts for this condition
~OR~
if (false = true) -> FALSE -> (if there's no 'else ifs' to check) -> (go to the 'else' condition, if there is one) -> run the nested scripts for the 'else' condition

XanMag
14 Feb 2016, 16:25
I have attached the .aslx file if you need to download it and look at it in the GUI.

But, here are the steps I used:

1. Make a door object. Choose whether to make it 'scenery' or not. I did not.
2. Add an 'IF' script for the door description. Select 'object does not have flag' and set the object to door and type in kicked in the flag name box.
3. Add a print message script to describe the door.
4. In the 'Else' part of this script, add a print message script and describe the door once it is kicked in.
5. Go to the 'verbs' tab of the door and add push. Print a message to describe your push action.
6. Add kick to the verbs list. Add an 'If' script. Select 'object does not have flag' and set the object to door and type in kicked in the flag name box.
7. Add a print message script asking the question "It looks pretty formidable. Are you sure you want to try and kick this door?"
8. Add a 'Get Input' script. In the then Run Script section of this box, add a 'Switch' script.
8. In the 'Switch' script type this --> LCase(result)
9. Click 'Add Case' and type something like this in: "yes","yeah","yep","yea","y"
10. In this new box that pops up, add an 'If' script. Select 'object does not have flag' and set the object to door and type in kicked in the flag name box.
11. Add a print message script describing your 'kick'. Also add a 'Set object flag' script and set the object door and type in kicked in the flag name box.
12. In the 'Else' part of this script add some snarky comment about kicking the door again.
13. Close the box and add another 'case' to the switch script. I typed in this: "no","nope","nay","n","nah"
14. In this box, run a print message script indicating that the player changed their mind to kick the door.
15. In the default of the 'switch' script add a message indicating that the input wasn't understood or some other message about not answering the question.
---
16. I added a 'push' verb to the door and printed a message saying pushing the door didn't work and suggesting a more "forceful" approach. Be sure to add an 'If' script here too so the player doesn't try to push an already kicked in door!
---
17. I created an exit to the room (that is being blocked by the door) as I normally would. But there is a little box there that says 'Run a script instead of moving the player automatically'. Click that.
18. Run an 'If' script and select 'object does not have flag' and set the object to door and type kicked in the flag name box.
19. In the 'then' part of this script, print a message stating that there is a heavy door blocking your path.
20. In the 'Else' part of this script, print a message (if you wish) saying that the player walks past the busted door and in to the next room.
21. Lastly, run a 'move object' script and set the object to 'player' (or whatever your player name is) and select object room2 (or whatever name the exit leads to)

If you have any questions, let me know. I did this without proofreading it, so let me know if the steps aren't clear or are inaccurate! Good luck!


Enju
17 Feb 2016, 20:56
thanks a lot got it working now!