Hello Everyone!
I have a text parser up and running in my small "learning AGS" test project. I am trying to recreate something like the old-school World Builder games from the Macintosh Classic days, so I have two GUIs: one that 'narrates', i.e. tells the player where they are, what's going on (text adventure style); and one for entering in commands. I have both GUIs visible at all times. Things are working as expected, but I feel like I'm on the wrong path here with the scripting. I am finding I must be very specific regarding what the player inputs â€" Instead of telling the parser to look for certain key words, no matter how they were entered, it appears that the key words must be parsed in an exact order/combination. I must be doing something wrong.
For example, in my test room I have a paperclip on the floor. There is a locked door. I have successfully created a brief script where the user can type "take paperclip", and the paperclip object 'leaves' the scene and is added to the player's inventory. However, I also want the same script to be executed if something unpredictable like, "go over and take the stupid metal paperclip which I will then use to pick the lock on the door" is entered. From my understanding, in order for that line to be parsed correctly, there would need to be a line in the script that looks something like: if (Parser.Said("anyword take,get,grab anyword anyword paperclip rol")). If I don't have a line like that, then even entering "take the metal paperclip" would result in the parser halting.
Obviously I can't predict everything that someone is going to try and type. In the days of World Builder, I just scripted something like IF{TEXT=take}AND{TEXT=paperclip}, and it would cover any amount of random gibberish the player typed. As long as the words "take" and "paperclip" appeared somewhere in the input, the code would proceed.
Given what I'm looking to do, should I be using the parser at all? Should I instead be using something that checks the content of Strings? Also, I know text parsers are old news these days, but I have a huge soft spot for them and I think they add a lot to game play.
Thank you all! I have been looking at AGS for years now and finally decided to take the plunge and learn this.
Here is my parser in global script:
Code: ags
And here is my code in the room:
Code: ags
I have a text parser up and running in my small "learning AGS" test project. I am trying to recreate something like the old-school World Builder games from the Macintosh Classic days, so I have two GUIs: one that 'narrates', i.e. tells the player where they are, what's going on (text adventure style); and one for entering in commands. I have both GUIs visible at all times. Things are working as expected, but I feel like I'm on the wrong path here with the scripting. I am finding I must be very specific regarding what the player inputs â€" Instead of telling the parser to look for certain key words, no matter how they were entered, it appears that the key words must be parsed in an exact order/combination. I must be doing something wrong.
For example, in my test room I have a paperclip on the floor. There is a locked door. I have successfully created a brief script where the user can type "take paperclip", and the paperclip object 'leaves' the scene and is added to the player's inventory. However, I also want the same script to be executed if something unpredictable like, "go over and take the stupid metal paperclip which I will then use to pick the lock on the door" is entered. From my understanding, in order for that line to be parsed correctly, there would need to be a line in the script that looks something like: if (Parser.Said("anyword take,get,grab anyword anyword paperclip rol")). If I don't have a line like that, then even entering "take the metal paperclip" would result in the parser halting.
Obviously I can't predict everything that someone is going to try and type. In the days of World Builder, I just scripted something like IF{TEXT=take}AND{TEXT=paperclip}, and it would cover any amount of random gibberish the player typed. As long as the words "take" and "paperclip" appeared somewhere in the input, the code would proceed.
Given what I'm looking to do, should I be using the parser at all? Should I instead be using something that checks the content of Strings? Also, I know text parsers are old news these days, but I have a huge soft spot for them and I think they add a lot to game play.
Thank you all! I have been looking at AGS for years now and finally decided to take the plunge and learn this.
Here is my parser in global script:
function txtUserInput_OnActivate(GUIControl *control)
{
String input = txtUserInput.Text;
Parser.ParseText(input);
CallRoomScript(1);
if (Parser.SaidUnknownWord())
{
lRoomDescription.Text = ("Huh?");
}
txtUserInput.Text = "";
}
And here is my code in the room:
function on_call (int value)
{
if (value == 1)
{
if (Parser.Said("take,pick,lift anyword paperclip rol")||(Parser.Said("take,pick,lift paperclip rol")))
{
if (player.HasInventory(iPaperclip) == false)
{
if (doorlocked == true)
{
oPaperclip.Visible = false;
lRoomDescription.Text = ("You now have the paperclip.");
player.AddInventory(iPaperclip);
}
else
{
lRoomDescription.Text = ("The paperclip is stuck in the door handle. You cannot retrieve it.");
}
}
else
{
lRoomDescription.Text = ("You already have the paperclip.");
}
}
}
}