ID:273973
 
How would it be possible to have findtext locate "Hi" in "hi my name is bob." and send a command thats related to it, but at the same time not send the command when "thing" is said. Seeing as "thing" also has "hi" in it as well. Id also like to refrain from using FindTextEx seeing as not everyone uses correct spelling or cap. online. Thanks for any help you guys can provide.
You can use <code>lowertext()</code> included with <code>findtext()</code> to compare text strings.
In response to Neimo
Neimo wrote:
You can use <code>lowertext()</code> included with <code>findtext()</code> to compare text strings.

Example?
In response to D-Cire
There are examples in the reference.
You could try using findtext to find the spaces, or certain key characters around the string you want, or even using a command word such as 'SYSHELP:'

mob/verb/Say1(var/T as text)
/*The space method*/
if(findtext(T," hi ")||findtext(T,"hi "))
world<<"Hey"
//Do stuff
mob/verb/Say2(var/T as text)
/*The key character method*/
if(findtext(T,"{") && findtext(T,"}"))
var/Tex = copytext(T,(findtext(T,"{")+1),findtext(T,"}"))
switch(Tex)
if("hi")
world<<"Hey"
//Do stuff
mob/verb/Say3(var/T as text)
/*The command method*/
if(copytext(T,1,9) == "SYSHELP:")
var/Tex = copytext(T,10)
switch(Tex)
if("hi")
world<<"Hey"
//Do stuff
In response to El Wookie
El Wookie wrote:
You could try using findtext to find the spaces, or certain key characters around the string you want, or even using a command word such as 'SYSHELP:'

> mob/verb/Say1(var/T as text)
> /*The space method*/
> if(findtext(T," hi ")||findtext(T,"hi "))
> world<<"Hey"
> //Do stuff
> mob/verb/Say2(var/T as text)
> /*The key character method*/
> if(findtext(T,"{") && findtext(T,"}"))
> var/Tex = copytext(T,(findtext(T,"{")+1),findtext(T,"}"))
> switch(Tex)
> if("hi")
> world<<"Hey"
> //Do stuff
> mob/verb/Say3(var/T as text)
> /*The command method*/
> if(copytext(T,1,9) == "SYSHELP:")
> var/Tex = copytext(T,10)
> switch(Tex)
> if("hi")
> world<<"Hey"
> //Do stuff
>


I was more looking for the first thing you stated wookie, thanks! Im trying to make a sort of "Reply Bot" may you call it? Not really for a game or anything just as something i want to do, and this was confusing me :P
In response to El Wookie
If I remember how findtext() works, your Say1 has an error in it, because it will respond to things such as "I like the letter phi a lot" and not to strings such as "hi". This might work better:

<code>if (findtext (" [T] ", " hi ")||findtext (" [T] "," hi. "||findtext(" [T] "," hi, "), ...)</code> (fill in the remaining punctuation marks)

Edit: I guess it's cleaner if you just have a proc that strips punctuation marks altogether

var/list/punct = list(...) // all punctuation marks
proc/stripPunctuationMarks(text)
for (var/i = 1, i <= len(text), i ++)
var/character = copytext (text, i, i+1)
if (punct.Find(character))
text = copytext (text, 1, i) + " " + copytext(text, i+1)
return text

(Haven't tested)

So then the only conditional you need is:

<code>if (findtext (" [stripPnctMarks(T)] ", " hi ")</code>
In response to Toadfish
Wouldn't that require a space before the word itself to trigger?
In response to Lugia319
No, because we're parsing " [text] " and not "[text]".
In response to Toadfish
Toadfish wrote:
No, because we're parsing " [text] " and not "[text]".

I basically just made it check for "Hi.", "Hi!", "Hi?" or " Hi " And mad an add punctuation point proc to add a period if they just typed "Hi". Anything else will just end up in a random response. Not the best way, but better than i originally had planed.
In response to D-Cire
Another way you could do it, a far more accurate one, would be to split up the text string into a list via spaces, so for example:
'Hi there you! This is cool!'
Would become a list as such
list("Hi","there","you!","This","is","cool!")

Obviously you'd need a few check for punctuation and what not, but as far as I can see this would be the best solution to your problem. (Now that I fully understand it =P)
In response to El Wookie
El Wookie wrote:
Another way you could do it, a far more accurate one, would be to split up the text string into a list via spaces, so for example:
'Hi there you! This is cool!'
Would become a list as such
list("Hi","there","you!","This","is","cool!")

Obviously you'd need a few check for punctuation and what not, but as far as I can see this would be the best solution to your problem. (Now that I fully understand it =P)

Lol, i see. Well i dont really know how that would be done. Ive stated before im a fast learner, but im still pretty new to the DM Language.
In response to D-Cire
proc
split(txt,d)
ASSERT(istext(txt))
ASSERT(d)
var/pos = findtext(txt, d)
var/start = 1 //Thank you Forum_Account
. = list()
while(pos > 0)
. += copytext(txt, start, pos)
start = pos + 1
pos = findtext(txt, d, start)

. += copytext(txt, start)

mob/verb/Say4(var/T as text)
var/list/words = split(T," ")
for(var/i in words)
if(i == "Hi")
world<<"Hey"
//Do stuff


Using a proc from a library by Forum_Account to easily split the text string into a list of words.
In response to El Wookie
You're welcome =)
In response to Forum_account
Forum_account wrote:
You're welcome =)
Thank you both! =3
In response to Toadfish
I tried hard to think of any words which ended in 'hi', and when I couldn't think of any I added the second option to include the space at the end.

Sorry for being less smarterer than you D: