Lua function string.find() not working

Announcements, support questions, and discussion for the Dialogue System.
Post Reply
Jaramal
Posts: 6
Joined: Wed May 03, 2017 3:19 am

Lua function string.find() not working

Post 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.)
User avatar
Tony Li
Posts: 22062
Joined: Thu Jul 18, 2013 1:27 pm

Re: Lua function string.find() not working

Post 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
Jaramal
Posts: 6
Joined: Wed May 03, 2017 3:19 am

Re: Lua function string.find() not working

Post by Jaramal »

Thanks a lot ! That did the trick. ;-)
Post Reply