cannot change value with a timer

Hi, I’m reporting issues when I try to change a variable value with a timer.

Actually I’m using the following code to perform that:

local counter = math.random(100, 350) local function changeCounterValue() counter = math.random(130, 170) end tmr = timer.performWithDelay(1500, changeCounterValue, 0)

but It just doesn’t work?

Could you help me? 

Thanks in advance!

Why you think it doesn’t work?

because i have 

local wall = display.newRect(0, \_H/2-160, 10, counter)

and I want to change every 1500 milliseconds its height (in this case “counter”)

I tried many times to perform that but it still doesn’t work

But you do not change height at all. You must: wall.height = counter and put it inside timer function

Try that:

[lua]
local counter = math.random( 130, 170 )

local wall = display.newRect(0, _H/2-160, 10, counter)

wall:setFillColor( 0 )

wall.x = display.contentCenterX

wall.y = display.contentCenterY

local function changeCounterValue( event )

  local counter = math.random( 130, 170 )

  wall.height = counter

end

tmr = timer.performWithDelay( 1500, changeCounterValue, 0 )
[/lua]

Thank you both!! It’s works as it should! :slight_smile:

Why you think it doesn’t work?

because i have 

local wall = display.newRect(0, \_H/2-160, 10, counter)

and I want to change every 1500 milliseconds its height (in this case “counter”)

I tried many times to perform that but it still doesn’t work

But you do not change height at all. You must: wall.height = counter and put it inside timer function

Try that:

[lua]
local counter = math.random( 130, 170 )

local wall = display.newRect(0, _H/2-160, 10, counter)

wall:setFillColor( 0 )

wall.x = display.contentCenterX

wall.y = display.contentCenterY

local function changeCounterValue( event )

  local counter = math.random( 130, 170 )

  wall.height = counter

end

tmr = timer.performWithDelay( 1500, changeCounterValue, 0 )
[/lua]

Thank you both!! It’s works as it should! :slight_smile: