attempt to index upvalue (a boolean value)

i has this prototype storyboard that contains this code 
[spoiler]

--prototype.lua local storyboard = require( "storyboard" ) local scene = storyboard.newScene() local Controller = require("scripts.Controller") --local var here --buttons local buttonLeft, buttonRight, buttonUp, buttonDown --groups local buttonGroup -- Called when the scene's view does not exist: function scene:createScene( event ) local group = self.view buttonLeft = Controller.buttonLeft --runtime error:attempt to index upvalue "Controller" (a boolean value) buttonRight = Controller.buttonRight buttonUp = Controller.buttonUp buttonDown = Controller.buttonDown buttonGroup = display.newGroup() buttonGroup:insert(buttonLeft) buttonGroup:insert(buttonRight) buttonGroup:insert(buttonUp) buttonGroup:insert(buttonDown) group:insert(buttonGroup) end --suceeding part of storyboard template didnt change

[/spoiler]

then im putting an arrow touch buttons at the lower left corner of the screen,… here’s the code

[spoiler]

--Controller.lua --arrow buttons local button\_up, button\_down, button\_left, button\_right --variables local defaultAlphaButton defaultAlphaButton = 0.5 function buttonDown() button\_down = display.newImage("Assets/Images/buttonDown.png") button\_down.x = button\_left.contentWidth+button\_down.width/2 button\_down.y = display.contentHeight-button\_down.width/2 button\_down.alpha = defaultAlphaButton return button\_down end function buttonLeft() button\_left = display.newImage("Assets/Images/buttonLeft.png") button\_left.y = display.contentHeight-button\_down.contentHeight-button\_left.height/2 button\_left.alpha = defaultAlphaButton return button\_left end function buttonRight() button\_right = display.newImage("Assets/Images/buttonRight.png") button\_right.x = button\_left.width+button\_down.width+button\_right.width/2 button\_right.y = display.contentHeight-button\_down.contentHeight-button\_right.height/2 button\_right.alpha = defaultAlphaButton return button\_right end function buttonUp() button\_up = display.newImage("Assets/Images/buttonUp.png") button\_up.x = button\_left.width+button\_up.width/2 button\_up.y = display.contentHeight - button\_down.height - button\_left.height - button\_up.height/2 button\_up.alpha = defaultAlphaButton return button\_up end  

 
[/spoiler]

i’ve experiencing error [see the runtime error comment on first code] and cant trace why receiving this problem

btw i also tried commenting the x and y values of each button [probably there is the problem] but still getting the same error, so i guess it is not on the x and y values

thanks in advance

is that the entire Controller.lua file

is Controller.lua the file name

if so then you should be calling

Controller = require'Controller'

my Controller.lua is currently located in “scripts” folder. [i followed what i read [here](http://coronalabs.com/blog/2012/07/10/best-practices-for-organizing-projects/)]

However, if you were to place util.lua into the ‘scripts’ folder, the above line would not work. You would instead need to specify the sub-directory using the directory name followed by a period (dot) and then the module name, like so:

local util = require( “scripts.util” )

should i remove it to the scripts folder ???

no, your folder structure (and module naming) is fine.  your problem is that Controller.lua doesn’t create/return a table object, just defines a couple local vars and some global functions.  look for more thorough examples, but basic structure like this:

-- Controller.lua local M = {} function M:buttonDown() end -- et cetera return M

now the “thing” returned by require() will be a table containing the methods you expect, callable as Controller:buttonDown().  then be sure when doing your buttonGroup:insert you CALL those functions (with the parenthesis, to get their return values)… as you have it written now (without parenthesis) you’re trying to insert a reference to a function into the group, which won’t work.  hth

[quote=“davebollinger,post:4,topic:316225”]

no, your folder structure (and module naming) is fine.  your problem is that Controller.lua doesn’t create/return a table object, just defines a couple local vars and some global functions.  look for more thorough examples, but basic structure like this:

-- Controller.lua local M = {} function M:buttonDown() end -- et cetera return M

now the “thing” returned by require() will be a table containing the methods you expect, callable as Controller:buttonDown().  then be sure when doing your buttonGroup:insert you CALL those functions (with the parenthesis, to get their return values)… as you have it written now (without parenthesis) you’re trying to insert a reference to a function into the group, which won’t work.  hth [/quote]

it worked!!

thanks a lot  :slight_smile:

now i will fix my x and y values but i guess i can do it…

is that the entire Controller.lua file

is Controller.lua the file name

if so then you should be calling

Controller = require'Controller'

my Controller.lua is currently located in “scripts” folder. [i followed what i read [here](http://coronalabs.com/blog/2012/07/10/best-practices-for-organizing-projects/)]

However, if you were to place util.lua into the ‘scripts’ folder, the above line would not work. You would instead need to specify the sub-directory using the directory name followed by a period (dot) and then the module name, like so:

local util = require( “scripts.util” )

should i remove it to the scripts folder ???

no, your folder structure (and module naming) is fine.  your problem is that Controller.lua doesn’t create/return a table object, just defines a couple local vars and some global functions.  look for more thorough examples, but basic structure like this:

-- Controller.lua local M = {} function M:buttonDown() end -- et cetera return M

now the “thing” returned by require() will be a table containing the methods you expect, callable as Controller:buttonDown().  then be sure when doing your buttonGroup:insert you CALL those functions (with the parenthesis, to get their return values)… as you have it written now (without parenthesis) you’re trying to insert a reference to a function into the group, which won’t work.  hth

[quote=“davebollinger,post:8,topic:316225”]

no, your folder structure (and module naming) is fine.  your problem is that Controller.lua doesn’t create/return a table object, just defines a couple local vars and some global functions.  look for more thorough examples, but basic structure like this:

-- Controller.lua local M = {} function M:buttonDown() end -- et cetera return M

now the “thing” returned by require() will be a table containing the methods you expect, callable as Controller:buttonDown().  then be sure when doing your buttonGroup:insert you CALL those functions (with the parenthesis, to get their return values)… as you have it written now (without parenthesis) you’re trying to insert a reference to a function into the group, which won’t work.  hth [/quote]

it worked!!

thanks a lot  :slight_smile:

now i will fix my x and y values but i guess i can do it…