Answer the question
In order to leave comments, you need to log in
How to effectively compare text?
I am writing a MUD game. I want to make controls using commands that the user enters (like bash in Linux, for example). To be more specific: the player enters the command use health_potion
, the program processes the request (this is the question), then the program chooses to use the procedure use
with the parameter health_potion
, and not close the game
.
How should the program process the player's string in order to figure out which function to use?
Does she have to compare each character with the entire alphabet to decide what to do next?
Where to start digging? (resources) I tried to google, stumbled upon habr.
Ps Of course, I can use a bunch of if's, but...
Answer the question
In order to leave comments, you need to log in
In essence, you want to develop a state machine, there are tools for this
https://ru.wikipedia.org/wiki/Yacc
Use them
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question