Community

AGI Programming => AGI Syntax Help => Topic started by: claudehuggins on August 07, 2016, 05:59:44 PM

Title: Questions about ROL and anyword
Post by: claudehuggins on August 07, 2016, 05:59:44 PM
Note: I'm posting this in the AGI board because that's what I'm using, but I believe this could also apply to SCI. Let me know if this needs to be somewhere else.

I am attempting to create a statement in my global logic that gives a sarcastic quip when the player starts a sentence with "why" (since I noticed a lot of my playtesters were doing so facetiously). My attempt in doing this led to an issue that I may find the solution to useful in other situations.

My instinct was to use
Code: [Select]
if(said("why","rol")) {
print("Because that's just how the world works, %s3.");
}
Which worked fine for phrases like "why talk to the wizard" and other lines consisting of words in the WORDS.TOK file.

My issue is, if someone were to type something like "why are you so dumb", I'd want the quip to appear even though words like "dumb" and "so" aren't defined. Typing that with this setup gets the generic "I don't know X" message.

Is there a way to detect the presence of a word in a line, and flat-out ignore the entire rest of the line if it is found?

EDIT: I also considered using anyword after noticing the large block of code used for handling bad words, but upon doing a test having the engine parse a series of unknown words with a bad word among them, it doesn't see the word at all.
EDIT 2: Corrected my syntax in the example code because it was bugging me
Title: Re: Questions about ROL and anyword
Post by: OmerMor on August 08, 2016, 01:38:34 PM
I'm not knowledgeable enough in AGI, but perhaps Sierra's official documentation could be of help:
http://sciprogramming.com/community/index.php?topic=1617.0 (http://sciprogramming.com/community/index.php?topic=1617.0)
Title: Re: Questions about ROL and anyword
Post by: lskovlun on August 09, 2016, 10:32:40 PM
OK, so I've given this a bit of thought, not knowing anything about AGI and not having tested anything.
If this is possible at all, I think you need to look at re-parsing with the use of a helper string.
According to Omer's docs, there is a "%w1" directive that can be put in a string to refer to the first word in the input line. So I'm thinking along the lines of
Code: [Select]
parse("%w1");
if(said("why")) {
print("Because that's just how the world works, %s3.");
}
Note that this will interfere with your ordinary input handling (it will make the full input line inaccessible), so it needs to be done after all other input handling code. This approach can also be used in SCI to inject an input line into the ordinary input handler code, but if I were doing this in SCI, I would use wordFail/syntaxFail/semanticFail instead. SCI also doesn't have the %wn directive, nor a word.to.string command (another potentially useful feature).
Title: Re: Questions about ROL and anyword
Post by: lance.ewing on February 25, 2017, 12:25:18 PM
EDIT: I also considered using anyword after noticing the large block of code used for handling bad words, but upon doing a test having the engine parse a series of unknown words with a bad word among them, it doesn't see the word at all.

I realise that its been months since this was discussed, but it caught my eye this morning, mainly because I think that the solution I'm about to propose works in the original AGI interpreter but not in my C# interpreter  :(

Code: [Select]
if ((said("why") || said("why","anyword") || said("why","anyword","anyword") || said("why","anyword","anyword","anyword") || said("why","anyword","anyword","anyword","anyword"))) {
  print("Because that's just how the world works.");
  unknown_word_no = 0;
}

It seems to work from the testing I've done, but obviously only up to however many "anyword" variations you include. What I've noticed is that "anyword" matches both recognised words and unrecognised words. My interpreter is currently only matching recognised words, so I'll have to fix that now.
Title: Re: Questions about ROL and anyword
Post by: AGKorson on November 10, 2020, 03:27:09 PM
I realize I'm addressing a post that is EXTREMELY old, but I wanted to make sure that accurate information is provided in case anyone else comes here looking for an answer to the qestion.

The original problem posted is not an issue with AGI's handling of input; it's an issue of where commands are processed in the game's logic.

Code: [Select]
if (said("why", "rol"))
will return TRUE for any input that begins with "why", including "why" by itself, "why" followed by known words, and "why" followed by an unknown word (as long as haveInput[f2] is TRUE, and haveMatch[f4] is FALSE). The reason the original poster is getting the "I don't know X" message is because the check for unknown words is happening BEFORE the check for "why", "rol".

This is easy enough to demonstrate by putting the 'if' block at the beginning of Logic 0. You will get the desired response. As they say, 'timing is everything', and with AGI, it's even more important to know where you place code to make sure you get the results you want. The cyclic and linear nature of AGI programming can result in really strange results if you don't pay attention to the order of things.

(AND, if you also have an unknown word in your input, keep in mind that even after displaying the response to 'why', you may also get the "I don't know X" response, depending on how your game handles unknown words. The templates that have been around for years will show the "I don't know X" response even if a preceding 'said' command finds a match. You will need to either reset the unknown word value (v9) within your code block responding to "why", or you will need to edit your unknown word handler to not respond if a match has been found.)