I have been trying to build a debug menu that is populated by variables that I’d like to modify on the fly, but I have been running into problems when I attempt to modify them from inside another module. Here is a stripped down example of the “main.lua”:
[lua]
first_global_value = 5
second_global_value = 10
print( "first_global_value: " … first_global_value … " and second_global_value: " … second_global_value )
local external_mod = require( “external_mod” )
external_mod.modifyValue()
print( "first_global_value: " … first_global_value … " and second_global_value: " … second_global_value ).
[/lua]
and the “external_mod.lua”:
[lua]
local M = {}
local table_values = {
first_global_value,
second_global_value,
}
function M.modifyValue()
local i
for i = 1, #table_values do
table_values[i] = table_values[i] + 1
print( table_values[i] )
end
end
return M
[/lua]
The output is something like:
[lua]
first_global_value: 5 and second_global_value: 10
6
11
first_global_value: 5 and second_global_value: 10
[/lua]
I think when the variables are brought into the “table_values” table, the values are copied and not the references to the variables themselves.
Any ideas on how to fix this problem? Thanks, Allen