Changing local variable w / global function in lua

I have two scenarios and I cannot combine both scenarios into one. There must be two runs.

Script A is almost completely local, but it calls a global function several times. They are defined in Script B. I would like to know if it is possible that the function uses local variables inside Script A somehow.

This is true:

--Script A
local lastUpdateID = 308
local var1,var2=6,7
_G.writeDefinition(var1,var2)

--Script B
function _G.writeDefinition(var1,var2)
  -- Right here, is it possible that we can alter the 
  -- variable lastUpdateID? < (This is my question)
end

I tried looking in getfenvand setfenv, but they do not show that a local variable exists. The thing is that when Script A calls writeDefinition, it lastUpdateIDincreases by one. lastUpdateIDshould remain a local variable.

EDIT: Ryan Stein's solution worked, but I ran into another problem later in the scripts.

Now it looks like this:

local f_count=1
local function sell_lox()
    local sellID=5
    _G.writeDefinition(sellID,sellID.." PX_lvs")
end

. , , , , SellID writeDefinition. f_count writeDefinition?

+4
1

, debug.

function writeDefinition(var1, var2)
  local i, k, v = 0
  repeat -- Iterate through the calling function local variables.
    i = i + 1
    k, v = debug.getlocal(2, i)
  until k == 'lastUpdateID'
  debug.setlocal(2, i, v + 1) -- Increment lastUpdateID.
end
+1

All Articles