Overriding all commands in specific room

deadvermin97
08 Jul 2022, 04:07

I'm trying to do something similar to what's described here:
https://textadventures.co.uk/forum/quest/topic/3650/while-loop-that-loops-until-the-user-types-the-right-thing
where I'm waiting for a particular command, and throwing the same message for anything else the user might type.

However I don't really want to use get input{} cause they don't display the same way commands do (e.g. the users commands continue to be shown but inputs disappear). I tried making a room-specific command with the pattern #text# (and I would check if it matched the particular command I'm looking for) as I just assumed that would override everything else, but it seems that commands like look, inv or x self would still work as usual.

One possible solution I'm considering is just "faking" the command display (by printing the user's input as part of the message each turn) but I would still like to know why doesn't the #text# command in the room override everything like I thought it would and if there's any way I could still make that work, cause it just seems simpler. Tys.


mrangel
08 Jul 2022, 05:05

I tried making a room-specific command with the pattern #text# (and I would check if it matched the particular command I'm looking for) as I just assumed that would override everything else, but it seems that commands like look, inv or x self would still work as usual.

This should work. A command in the current room always takes priority. Can you show us the game (or an example game showing this issue)?


deadvermin97
08 Jul 2022, 05:47

Sorry, I just realised I don't even know how to put an attachment on forum posts 😅


mrangel
08 Jul 2022, 12:34

Sorry, I just realised I don't even know how to put an attachment on forum posts 😅

Sadly they don't do attachments. But if you upload it to the website you can post the address here. (You can publish a game with the privacy set to "only people I share the link with" or something, so other people can't see it, and then change it to public when the game is ready for release - although once published, you can only hide a game, not delete it, so it's on your "my games" page forever)


deadvermin97
09 Jul 2022, 06:53

Mmmm, here's a dropbox share link:
https://www.dropbox.com/s/jcm7w9sk6x261rw/Game.aslx?dl=0
hope that works.

In particular, x self is surprising here in that it neither displays my "intended" message nor the player's description, but the default.


mrangel
09 Jul 2022, 10:38

One alternative woild be giving the command a regular expression pattern like .* rather than #text#; as it doesn't capture the actual command typed, so the parser thinks it's more specific. But this really shouldn't be necessary.


deadvermin97
09 Jul 2022, 13:48

That worked, thanks so much!
Just in case anyone's interested, I had two room specific commands now: one with the other with the pattern .*, and another with the particular command pattern I'm waiting the player to type in.
I don't know if the order I created those commands matters but it was in the order as was described.


deadvermin97
09 Jul 2022, 16:30

Oh wait, actually I have one more question quite unrelated if that's okay!

How can I find the first key of a dictionary? I noticed they seem to be ordered as when I iterate over every key in a dictionary, it always happens in the order that I added the keys in. But what if I want to print the value of the first key only?


mrangel
09 Jul 2022, 21:44

Oddly enough, there doesn't seem to be an easy way to access the keys of a dictionary. And in the absence of a break/last command, it's not so easy to retrieve it. I would recommend making a function:

<function name="FirstKey" parameters="dict" type="string">
  foreach (key, dict) {
    return (key)
  }
</function>

Basically, using a foreach loop, and exiting it by using return on the first time through.


deadvermin97
11 Jul 2022, 02:05

God bless you dear sir


jord
14 Jul 2022, 12:40

such an informative thread, thanks everyone