Recognize player commands

Gng
30 May 2024, 09:32Is there a way to identify what the player did?
For example: I want to see if the player tries an exit but its locked which prints a msg hinting on how to unlock it.
if (game.pov.trapped){
lockexits = ScopeExits ()
while (ListCount (lockexits) > 0) {
x = PickOneObject (lockexits)
list remove (lockexits, x)
x.locked = true
x.lockmessage = "It won't budge! You have to do the ritual; there's no other way."
}
}
// player gets the lock message, but chooses to try the door again.
If (//player chooses to try to open door one more time//){
msg("Maybe I should check the Book of Tyke again. It could hold the secret to unlocking it.")
list add (booktyke.inventoryverbs , "Draken")
}
There are a lot of rooms that this can happen. These have exits. Should I just manually modify these exits' scripts? I was curious if there's a way to do it with a script/function.
mrangel
30 May 2024, 10:40If you want to check what command the player used, you can look at game.pov.currentcommandpattern
. So you could do something like:
if (game.pov.currentcommandpattern = go) {
// This script will only run if the player tried to go through an exit
}
However, in this case it looks like your script is running when the exits become locked, at which point they won't have tried them yet. In this case, it might make more sense to assign a script to the exit.
However, it might also make more sense to make a custom command.
If the command the player entered matches more than one command, it will use one that's in the room rather than the global command. So you could make a command that looks like this:
Name: fake_go
Pattern (regular expression): ^go to (?<exit>.*)$|^go (?<exit>.*)$|^(?<exit>north|east|south|west|northeast|northwest|southeast|southwest|in|out|up|down|n|e|s|w|ne|nw|se|sw|o|u|d)$
Script:
if ( not GetBoolean (exit, "tried")) {
msg ("It won't budge! You have to do the ritual; there's no other way.")
exit.tried = true
}
else {
msg ("It still won't budge.")
msg("Maybe I should check the Book of Tyke again. It could hold the secret to unlocking it.")
list add (booktyke.inventoryverbs , "Draken")
}
You can put this command inside a box somewhere (so it doesn't count as a global command), and then you can do:
MoveObjectHere (fake_go)
- to lock all exits by replacing the standardgo
command with a specific one for the current roomAddToInventory (fake_go)
- to allow the player to use exits again (putting a command in the inventory is a simple way to effectively disable it and let the default one run)

Gng
30 May 2024, 15:33These are all new stuff for me, thanks for the help!
What if the player is using the compass to move around instead of commands? Will the fake command work? or do I have to use game.pov.currentcommandpattern = go?
I tried using this code too:
if (game.pov.trapped){
lockexits = ScopeExits ()
while (ListCount (lockexits) > 0) {
x = PickOneObject (lockexits)
list remove (lockexits, x)
x.locked = true
x.lockmessage = "It won't budge! You have to do the ritual; there's no other way."
x.runscript = true
x.script = Script: firsttime{msg("It won't budge!")}otherwise{msg("You can leave") player.parent = this.to}
}
}
Obviously it didn't work which made me wonder is there a way to code a script attribute that will be defined midgame? (for scoped objects?)
mrangel
31 May 2024, 08:49What if the player is using the compass to move around instead of commands? Will the fake command work?
Clicking the compass buttons just types the direction name ("north", "south", etc) into the command bar and sends it immediately, so it should work just the same.
The pattern I gave for the fake command is exactly the same as the pattern given in English.aslx
for the go
command; so it will match exactly the same inputs. (If you're using another language, you could temporarily add the line msg (go.pattern)
to a script somewhere, to get it to tell you what the pattern should be)
Obviously it didn't work which made me wonder is there a way to code a script attribute that will be defined midgame?
Yes; you could do something like:
x.script => {
firsttime {
msg("It won't budge!")
}
otherwise {
msg("You can leave")
player.parent = this.to
}
}
The =>
operator assigns a script - that's why you have to use >=
for greater-than-or-equal-to numeric comparisons (some languages allow either form, but Quest doesn't)

Gng
01 Jun 2024, 15:11Appreciate your help!