object.x, object.y and require ()

You are returning moveBool from bg4_move. Therefore bg4 in main is not an image, it is a bool. You then try to access what amounts to moveBool.moveBool, which is obviously nil.

You don’t see any errors in bg4_move because you’re not doing anything illegal. Corona says, 'hey, you want to create some images and then return a bool from this module? No problem."

Only when you try to do something with a bool that you think is an image does an error occur.

I change code, now it’s not image or still? By the idea bool declares earler than any images and value also returns to bool. Or not? Error still shows anyway.

--bg4 start ----------------------------------------------------------------------------------------- local imgW = display.contentWidth local imgH = display.contentHeight local scrollSpeed = -1.5 local moveBool = true if moveBool == true then scrollSpeed = -1.5 else scrollSpeed = 0 end --bg4 move local bg4a = display.newImageRect("img/bg/bg4.png", 1024, 768) bg4a.x = imgW\*0.5; bg4a.y= imgH/2.4; local bg4b = display.newImageRect("img/bg/bg4.png", 1024, 768) bg4b.x = imgW\*1.5; bg4b.y= imgH/2.4; local bg4c = display.newImageRect("img/bg/bg4.png", 1024, 768) bg4c.x = imgW\*2.5; bg4c.y= imgH/2.4; local function move( event ) -- move backgrounds to the left by scrollSpeed, default is 2 bg4a.x = bg4a.x + scrollSpeed bg4b.x = bg4b.x + scrollSpeed bg4c.x = bg4c.x + scrollSpeed -- Set up listeners so when backgrounds hits a certain point off the screen, -- move the background to the right off screen if bg4a.x \< -512 then bg4a:translate( 2048, 0 ) end if bg4b.x \< -512 then bg4b:translate( 2048, 0 ) end if bg4c.x\< -512 then bg4c:translate( 2048, 0 ) end end -- Create a runtime event to move backgrounds Runtime:addEventListener( "enterFrame", move ) return moveBool ----------------------------------------------------------------------------------------- --bg4 end

In main.lua you have this code:

[lua]

local bg4 = require (“bg4_move”)

[/lua]

bg4 will be equal to whatever you return from bg4_move, just with a different name. Therefore:

  • moveBool is a boolean set to true

  • bg4 is a boolean set to true

  • they are the same object with different names

Therefore, when you try to access bg4.moveBool, that does not exist, because moveBool.moveBool does not exist.

If you want to return everything from bg4_move.lua, and have access to it all, you need to do something like this:

[lua]

local m = {}

m.moveBool = true

m.bg4a = …

m.bg4b = …

m.bg4c = …

return m

[/lua]

Now, bg4.moveBool will exist, as will bg4.bg4a, bg4.bg4b and bg4.gb4c.

If you never need access to the images again, just leave them as local rather than attaching them to ‘m’.

Now i have no any errors, but also no any affects when i try to set false for bg4:

--main.lua local bg4 = require ("bg4\_move") bg4.moveBool = false

--bg4\_move.lua local bg4State = {} local scrollSpeed = -1.5 bg4State.moveBool = true if bg4State.moveBool == true then scrollSpeed = -1.5 else scrollSpeed = 0 end return bg4State

Probably something wrong in the conditions block? If that is, why i can set false in bg4_move.lua and this will work and not when i set it in the main.lua?

Is that all the code? The code that checks whether moveBool is true or false only runs once. You need to either put it in an enterFrame listener that checks every frame, or create a function that is called manually each time you update moveBool.

Thanks again!