syntax with table and function

hi

i don’t know how do this function with my variable cnt.ProgressView…i have a syntax problem. corona ask to me a “(”…

what’s the good syntax ? 

local cnt={} cnt.ProgressView=4 local function test(cnt.ProgressView,k) print(cnt.ProgressView-k) end

test(cnt.progressView,1) --error

this works, but there is no way to put cnt.ProgressView directly in my declaration function ? :

local cnt={} cnt.ProgressView=4 local function test(t-k) print(t-k) end

test(cnt.ProgressView,1) --result : 3

If you’re declaring cnt.ProgressView as variable accessible throughout the scene/module, then you wouldn’t really need to pass it as a variable to a function. Conversely, if you wanted to have the function control two different variables, then using the (t,k) would be the right way to go.

First option I was referencing:

local cnt={} cnt.ProgressView=4 local function test(k) print(cnt.ProgressView-k) end

ok thanks for your assist.

good day :slight_smile:

Hi,

If the ProgressView you are referencing is the Corona widget, you can’t use it like that. You’ll need to track it differently.

If it is not the widget, then try changing the variable name.

Hope that helps.

Cheers.

If you’re declaring cnt.ProgressView as variable accessible throughout the scene/module, then you wouldn’t really need to pass it as a variable to a function. Conversely, if you wanted to have the function control two different variables, then using the (t,k) would be the right way to go.

First option I was referencing:

local cnt={} cnt.ProgressView=4 local function test(k) print(cnt.ProgressView-k) end

ok thanks for your assist.

good day :slight_smile:

Hi,

If the ProgressView you are referencing is the Corona widget, you can’t use it like that. You’ll need to track it differently.

If it is not the widget, then try changing the variable name.

Hope that helps.

Cheers.