alephmembeth / textadventure-from-scratch

Yet another side project; a text-based game in Godot.
2 stars 1 forks source link

Also allow for `go to x` and `talk to x` #2

Closed JKRhb closed 1 year ago

JKRhb commented 1 year ago

Currently, you can only use the go and talk commands without a particle (e.g., "to"), which leads to prompts such as go alley or talk guard. I think in the midterm, it could be nice to also allow for more "complete" sentences, such as go to alley or talk to guard.

alephmembeth commented 1 year ago

Good point! With 24af3128e38835bf3b00301b38daa394ac643f78, this should become possible for instances where one or two words are between verb and noun, as in go to the door.

JKRhb commented 1 year ago

Awesome, thank you for implementing this :)

With https://github.com/alephmembeth/textadventure-from-scratch/commit/24af3128e38835bf3b00301b38daa394ac643f78, this should become possible for instances where one or two words are between verb and noun, as in go to the door.

One thing I noticed in the commit: Could it be that it should rather be

  elif words.size() > 3: 
    second_word = words[-1].to_lower() 

instead of

https://github.com/alephmembeth/textadventure-from-scratch/blob/24af3128e38835bf3b00301b38daa394ac643f78/parser.gd#L30-L31

to actually get the last word?

alephmembeth commented 1 year ago

Just tested it to be sure; [3] gets the fourth word from the PackedStringArray words as intended. Thanks for the close look! :)

alephmembeth commented 1 year ago

Actually, this produces an error for one-word commands, so I'll reopen the issue. :'D

alephmembeth commented 1 year ago

Of course, you were right about calling -1! Now, c74f390a6e6a8372dfa65d43286b76d48f96142f should fix this.

JKRhb commented 1 year ago

Of course, you were right about calling -1! Now, c74f390 should fix this.

Awesome! :) Maybe, though, you could also use -1 for a catch-all condition after 0 and 1? That is, something like the following:

if words.size() == 0:
    return "No words were parsed."

elif words.size() == 1:
    second_word == ""

else:
    second_word = words[-1].to_lower()

(Since this would also cover the condition words.size() == 2, if I am not mistaken.)

alephmembeth commented 1 year ago

Oh, my tired eyes didn't catch that yesterday. Changed it accordingly in 97f3991cc632f7f304f213bdbe9f4325ebd934e7. :)