Page 1 of 1

[0.17.60]The lua function string.find cannot return the correct result

Posted: Thu Aug 15, 2019 10:26 am
by qegr
Translated by Google :)

The cause is always to return a value of 0 when counting the number of power switches, and then found that the function string.find problem, sometimes can not return the correct result when encountering a hyphen
1.png
1.png (200.96 KiB) Viewed 903 times

Re: [0.17.60]The lua function string.find cannot return the correct result

Posted: Thu Aug 15, 2019 10:36 am
by Klonan
You are using poor syntax,

You need to escape the `-` with `%`

So like this:

Code: Select all

/c local a = string.find("power-switch", "power%-switch") game.print(a)
Lua Documentation: https://www.lua.org/pil/20.1.html https://www.lua.org/pil/20.2.html

Re: [0.17.60]The lua function string.find cannot return the correct result

Posted: Thu Aug 15, 2019 12:42 pm
by qegr
This is really too embarrassing. :oops:
I have not learned the lua grammar,I will only imitate the example on the wiki.
I am sorry for wasting your time for this low-level problem.