[Resolved] assign by reference for listener reuse? how to do this to simply this attached code?

I’m trying to reuse event listeners here to minimize/simply the code. Issue is I’m still stuck with have to do if/then loops in the listener (see code). So questions are:

Q1. Is there way to assign a variable by reference in lua? (e.g. a = b, but such that it will be by reference)

Q2. If not any other ideas re how to simply the code in the listener below? Note imagine that there were more variables involved (e.g. say 10 lock objects), and for each one the number of steps you wanted to perform were greater. That is the overhead of not being able to “pass-by-reference” is then quite high in terms of duplicate code.

[code]
– Variables
local lock1Text, lock2Text
local lock1Value = 1
local lock2Value = 1

function createLock(parentGroup, x, y, name)
local newLockTextObj = display.newText("", 0, 0, native.systemFont, 40)
newLockTextObj.name = name
return newLockTextObj
end

lock1Text = createLock(lockGroup, 50, 100, “lock1”)
lock2Text = createLock(lockGroup, 100, 100, “lock2”)

lock1Text:addEventListener(“touch”, lock1TextTouchListener)
lock2Text:addEventListener(“touch”, lock1TextTouchListener)

local function lock1TextTouchListener(event)
if event.phase == “began” then

– QUESTION HOW TO AVOID HAVING TO RUN THOUGH IF’S HERE
if event.target.name == “lock1” then
lock1Value = lock1Value + 1
if lock1Value == 10 then lock1Value = 1 end
elseif event.target.name == “lock2” then
lock2Value = lock2Value + 1
if lock2Value == 10 then lock2Value = 1 end
end

end
return true
end
[/code] [import]uid: 140210 topic_id: 27999 reply_id: 327999[/import]

think I have it using this approach

local lockValues = {} -- Array for Lock Values  
lockValues.lock1 = 1  
lockValues.lock2 = 1  
local function lockTextTouchListener(event)  
 if event.phase == "began" then  
 local lockKey = event.target.name  
 lockValues[lockKey] = lockValues[lockKey] + 1  
 if lockValues[lockKey] \>= 10 then lockValues[lockKey] = 1 end  
 lockDisplayRefresh()   
 end  
 return true  
end  

[import]uid: 140210 topic_id: 27999 reply_id: 113286[/import]