Posted 16 October 2016 - 03:22 AM
So I am working on a little project that requires the use of a find and replace sort of feature, and I figure that using string.gsub() is the proper way to go about what I want to do. However, when I use this:
I figured that the variables oox, ox, ooy, and oy are the issue, but…
oox, ooy, oy, and ox are numbers that are getting converted into strings, and I am 100% sure strings are one of the ways gsub can be used to capture patterns, so what is wrong here?
--Read the file
local filer = fs.open('.gphkit/temp', "r")
local str = filer.readAll()
filer.close()
--variable calling
local fx = tostring(.. oox .. '--x-offset')
local fxr = tostring(.. ox .. '--x-offset')
local fy = tostring(.. ooy .. '--y-offset')
local fyr = tostring(.. oy .. '--y-offset')
--find and replace where the offsets are stored in the fid API
local str = string.gsub(str, fx, fxr)
local str = string.gsub(str, fy, fyr)
--embed into fid API
local filew = fs.open('.gphkit/temp', "w")
filew.write(str)
filew.close()
it gives an error saying: 'invalid pattern capture'I figured that the variables oox, ox, ooy, and oy are the issue, but…
oox, ooy, oy, and ox are numbers that are getting converted into strings, and I am 100% sure strings are one of the ways gsub can be used to capture patterns, so what is wrong here?