Page 1 of 1

Lua function string.find() not working

Posted: Wed May 03, 2017 3:40 am
by Jaramal
Hello,

First of all thanks for this amazing tool, spared us a lot of time and energy !
I'm facing a curious problem when trying to call the lua function : string.find() as a node condition.
For exemple :

Code: Select all

string.find("dog", "dog")
Seems to return false. When I call it in script :

Code: Select all

Lua.Run("string.find(\"dog\", \"dog\")");
=> HasReturnValue is always false. What is the correct synthax for the equivalent of c# method "string.contains" in Lua ?
(What I am trying to do is check if a Lua variable contains a specified string.)

Re: Lua function string.find() not working

Posted: Wed May 03, 2017 9:33 am
by Tony Li
Hi,

Lua's string.find() returns nil if it doesn't find a match, or a list of two numbers if it does find a match. The first number is the starting index of the match, and the second number is the ending index (starting from index 1). For example:

Code: Select all

return string.find("Yo dog", "dog")
returns the list { 4, 6 }. But this:

Code: Select all

return string.find("Yo dog", "cat")
returns nil.

You can check it in a node condition like this:
  • Dialogue Text: "Meow."
  • Conditions:

    Code: Select all

    string.find("Yo dog", "cat") == nil

Re: Lua function string.find() not working

Posted: Wed May 03, 2017 11:05 am
by Jaramal
Thanks a lot ! That did the trick. ;-)