[Resolved] passing external var (not the value itself) through a function

Hey there,

I have an external module, built like this:

local M = {  
var1 = "123",  
var2 = "456"  
}  
  
return M  

It’s included as data in every other lua file so I can always get access to it from outside like this:

print(data.var1)  

so that works fine. Now I have written some code somewhere else in the app:

 local table = {  
 {data.var1},  
 {data.var2}  
 }  
  
functions.refreshData(table)  

the last line reffers so this function:

 function refreshData(targets)  
  
 if data.error\_message == nil and data.networkerror == false and dataloaded(section) == true then  
  
 for i = 1, #targets do  
 print(targets[i][1])  
 end  
  
 elseif data.error\_message == nil and data.networkerror == false and dataloaded(section) == false then  
 print("data not loaded")  
 stopTimer(myTimerNew)  
 myTimerNew = timer.performWithDelay(500,refreshData(targets))  
 end  
  
 end  

as you can see I have a timer which is reloading the function refreshData() in case that the data (which the app requests in the background) is not there yet.

my problem is that the function which I pass to the table to, doesn’t seem to get the object data.var1 and data.var2 itself but already the values so everything I get printed out is always NIL. But I know that the data got updated successfully in the meantime.

how can I make a mapping to the var-obj from the data module instead of passing the values?

any help appreciated,
roman [import]uid: 140000 topic_id: 33180 reply_id: 333180[/import]

are you using ‘table’ as the name of the table holding the data???
‘table’ is a reserved word and is going to be the issue.

try:

local myTable = {
{data.var1},
{data.var2}
}

functions.refreshData(myTable)
hope that helps! [import]uid: 148857 topic_id: 33180 reply_id: 131779[/import]

hello cyberparkstudios,

thank you for your help. I know what you mean but unfortunately it doesn’t make any difference.

It already works because I get the table in refreshData(). By calling the function it gave him the value of var1 and var2 at the time that the function was called. it submits the value of data.var1 and data.var2. but it didn’t give me their names so that I could call them again.

for example this in refreshData() works:

print( data.var1 )  

this doesn’t:

print( targets[i][2] )  

do you know what I mean?

it’s similar with calling a function through a function. you can do it when you pass it like a string and put a () on the end. I would like to have it for the var. I don’t know if it’s possible. [import]uid: 140000 topic_id: 33180 reply_id: 131836[/import]

ha, actually that did the trick.

I passed it by using a function:

  
 local table = {  
  
 {function() return data.var1 end},  
 {function() return data.var2 end}  
  
 }  
  

later I get it by using () at the end of targets[i][2]

[code]

for i = 1, #targets do
local t = targets[i]2
print(t)
end

[/code] [import]uid: 140000 topic_id: 33180 reply_id: 131839[/import]

are you using ‘table’ as the name of the table holding the data???
‘table’ is a reserved word and is going to be the issue.

try:

local myTable = {
{data.var1},
{data.var2}
}

functions.refreshData(myTable)
hope that helps! [import]uid: 148857 topic_id: 33180 reply_id: 131779[/import]

hello cyberparkstudios,

thank you for your help. I know what you mean but unfortunately it doesn’t make any difference.

It already works because I get the table in refreshData(). By calling the function it gave him the value of var1 and var2 at the time that the function was called. it submits the value of data.var1 and data.var2. but it didn’t give me their names so that I could call them again.

for example this in refreshData() works:

print( data.var1 )  

this doesn’t:

print( targets[i][2] )  

do you know what I mean?

it’s similar with calling a function through a function. you can do it when you pass it like a string and put a () on the end. I would like to have it for the var. I don’t know if it’s possible. [import]uid: 140000 topic_id: 33180 reply_id: 131836[/import]

ha, actually that did the trick.

I passed it by using a function:

  
 local table = {  
  
 {function() return data.var1 end},  
 {function() return data.var2 end}  
  
 }  
  

later I get it by using () at the end of targets[i][2]

[code]

for i = 1, #targets do
local t = targets[i]2
print(t)
end

[/code] [import]uid: 140000 topic_id: 33180 reply_id: 131839[/import]

Hello friend I found this topic useful and found great app software to make free calls for iPhone and android using this free app for calls. [import]uid: 234713 topic_id: 33180 reply_id: 144853[/import]

Hello friend I found this topic useful and found great app software to make free calls for iPhone and android using this free app for calls. [import]uid: 234713 topic_id: 33180 reply_id: 144853[/import]

Hello friend I found this topic useful and found great app software to make free calls for iPhone and android using this free app for calls. [import]uid: 234713 topic_id: 33180 reply_id: 144853[/import]

Hello friend I found this topic useful and found great app software to make free calls for iPhone and android using this free app for calls. [import]uid: 234713 topic_id: 33180 reply_id: 144853[/import]