Issue returning value from module class

Hi all on my second day of learning Lua and corona. Trying to get to grips with some OOP and need a little help trying to resolve a issue I cant seem to suss.

I have created this module class for a scrolling back ground which is working correctly apart from I can not work out how to “Return” the heightTravelled variable to my calling script, here the class:

  
  
function new(imageSelection)  
 local speed = 0.02  
  
 heightTravelled = 0  
  
 local sky = display.newImage(imageSelection)  
 sky:setReferencePoint(display.CenterLeftReferencePoint)  
 sky.x = 0  
 sky.y = 0  
  
 local sky2 = display.newImage(imageSelection)  
 sky2:setReferencePoint(display.CenterLeftReferencePoint)  
 sky2.x = 0  
 sky2.y = 480  
  
  
 function sky:velocity(value)  
 speed = value  
 end  
  
 function sky:distance()  
 return heightTravlled  
 end  
  
 local function addHeight()  
  
 heightTravelled = heightTravelled + 480  
 print(heightTravelled)  
  
 end  
  
 local tPrevious = system.getTimer()  
  
 local function move(event)  
 local tDelta = event.time - tPrevious  
 tPrevious = event.time  
  
 local yOffset = ( speed \* tDelta )  
  
 sky.y = sky.y + yOffset  
 sky2.y = sky2.y + yOffset  
  
 if (sky.y + sky.contentHeight-240) \> 960 then  
 sky:translate( 0, -960)  
 addHeight()  
 end  
  
 if (sky2.y + sky2.contentHeight-240) \> 960 then  
 sky2:translate(0, -960)  
 addHeight()  
 end  
  
 end  
  
 Runtime:addEventListener( "enterFrame", move )  
  
 return sky, heightTravlled  
end  

Here is a snippet from my calling script as you can see I have worked out how to pass variables to functions in the class just cant seem to get a value returned.

[code] – call Module to creat scrolling sky

local scrollingSky = ScrollingDown.new(“basicCloudSky.png”)

scrollingSky:velocity(0.10)

– Would like to get value returned e.g. something like but it does not work

h = scrollingSky:distance()

[/code]

Much appreciated [import]uid: 118379 topic_id: 20869 reply_id: 320869[/import]

Typo on line 25

should be “heightTravelled” [import]uid: 84637 topic_id: 20869 reply_id: 82295[/import]

It’s also a typo on line 60.

And a relatively basic question - but what happens to the second return value in this case? If I wanted to find out the value of heightTravelled would it just be

[code]print(scrollingSky.heightTravelled)

– or maybe a table?

print(scrollingSky[2])[/code]

I never really saw something on lua and handling multiple returns. [import]uid: 41884 topic_id: 20869 reply_id: 82317[/import]

What a dick lol, thanks I should have noticed that. Im very bad at spelling, I have spelling disease. :slight_smile:

Will retry when I get home later, it all makes sense. [import]uid: 118379 topic_id: 20869 reply_id: 82444[/import]

Does any one else think the terminal is whack on osx. [import]uid: 118379 topic_id: 20869 reply_id: 82447[/import]

I will let you know, I was experiencing issues and was experimenting with different ways but none worked due to typos on all attempts. It will be nice if second return value does work in that way. [import]uid: 118379 topic_id: 20869 reply_id: 82449[/import]