Converting the player's commands into text?

I’m trying to find a way to convert the player’s commands into text, and then analyze the text. If I wanted to, say, check whether the first letter of the player’s commands started with “a”, how could I do this? To be clear, this is specifically what the player typed - so if “analyze” is a synonym for “look”, typing “analyze” should be fine, but typing “look” will be a problem. Any help is appreciated,
Thanks!

1 Like

First, you have to retrieve the command. If you’re in (rewrite $Words into $NewWords), then $Words is your command. If you’re somewhere else (e.g. in an action), then you can use the global (last command was $) (which isn’t documented so it could change in future versions of the standard library).

You also have to bear in mind that a command can contain more than one action. If the player types “attack it then look at it” and you check in the look action whether the command starts with an “a”, it will succeed although the word that made the look action happen started with an “l”.

Anyway, once you have the command, you can use (split word $ into $) to get the letters of a word.

So to check the first letter of the first word:

([$FirstWord | $] starts with $Letter)
    (split word $FirstWord into [$Letter | $])

%% And then:
(on every tick)
    (if) (last command was $Cmd) ($Cmd starts with @a) (then)
        (par) Your last command started with an "a"!
    (endif)
3 Likes

That sure did the trick. Thanks so much!