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

Bugs that are actually features.
qegr
Burner Inserter
Burner Inserter
Posts: 14
Joined: Fri Aug 02, 2019 7:11 pm
Contact:

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

Post 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 879 times
User avatar
Klonan
Factorio Staff
Factorio Staff
Posts: 5304
Joined: Sun Jan 11, 2015 2:09 pm
Contact:

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

Post 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
qegr
Burner Inserter
Burner Inserter
Posts: 14
Joined: Fri Aug 02, 2019 7:11 pm
Contact:

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

Post 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.
Post Reply

Return to “Not a bug”