Post your best Lua script examples here

User avatar
By manoelps
#29205 Hi guys, I'm trying to split a string into pieces, the Lua interpreter works, but the ESP shows the error: init.lua: 14: attempt to call field 'split' (a nil value)

Someone ever needed to split a string?

What do I need to get all the values of a url and assign variables example: http://192.168.4.1/?SSID=MySSID&Passwor ... MyNickName

If someone has an example will be grateful.

My code :
Code: Select allfunction string:split(delimiter)
  local result = { }
  local from  = 1
  local delim_from, delim_to = string.find( self, delimiter, from  )
  while delim_from do
    table.insert( result, string.sub( self, from , delim_from-1 ) )
    from  = delim_to + 1
    delim_from, delim_to = string.find( self, delimiter, from  )
  end
  table.insert( result, string.sub( self, from  ) )
  return result
end

delimiter = string.split("Manoel&Pereira&dos&santos ","&")

print(delimiter[1])
print(delimiter[2])
print(delimiter[3])
print(delimiter[4])



return error: init.lua:14: attempt to call field 'split' (a nil value)