In guitar.lua change it back to dots.createCircle
It’s M.createCircle inside the module (M is for Module), but your refer to it as “dots” in your other modules.
Rob
In guitar.lua change it back to dots.createCircle
It’s M.createCircle inside the module (M is for Module), but your refer to it as “dots” in your other modules.
Rob
I don’t want to give up…
and I don’t want to bother you so much
but it just doesn’t work…
– dots.lua
-- dots.lua local M = { } M.dot = {} -- table of individual dots. function M.createCircle (group) local separacion = 40 local initialX = display.contentCenterX - 190 local initialY = display.contentCenterY local distance = 30 for i=1, 10 do M.dot[i] = display.newImageRect ("images/circleYes.png", 60, 60) group:insert( M.dots[i] ) M.dot[i].x = initialX + (separacion\*i) M.dot[i].y = initialY + distance\*1 M.dot[i]:scale(.5, .5) end end return M
–guitar.lua
local storyboard = require( "storyboard" ) local dots = require("dots") local scene = storyboard.newScene() ------------------------------------------------------------------------------------------ -- --==\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*[CREATE SCENE]\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*++-- -- ------------------------------------------------------------------------------------------ function scene:createScene( event ) local group = self.view dots.createCircle (group) end
it seems to be really difficult to do this…but I know for sure we’ll make it work
I notice another thing…
in dots.lua I have – M.dot = { } ----- with no “s”
and in guitar.lua I have – dots.createCircle ----- with “s”
do that has something to do?
I change both ways and it doesn’t work any way
What error are you getting now?
this one
File: dots.lua
Line: 13
Attempt to index field ‘dots’ (a nil value)
and the only things I have is this
dots.lua
-- dots.lua local M = { } M.dot = {} -- table of individual dots. function M.createCircle (group) local separacion = 40 local initialX = display.contentCenterX - 190 local initialY = display.contentCenterY local distance = 30 for i=1, 10 do M.dot[i] = display.newImageRect ("images/circleYes.png", 60, 60) group:insert( M.dots[i] ) M.dot[i].x = initialX + (separacion\*i) M.dot[i].y = initialY + distance\*1 M.dot[i]:scale(.5, .5) end end return M
and guitar.lua
--guitar.lua local storyboard = require( "storyboard" ) local dots = require("dots") local scene = storyboard.newScene() ------------------------------------------------------------------------------------------ -- --==\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*[CREATE SCENE]\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*++-- -- ------------------------------------------------------------------------------------------ function scene:createScene( event ) local group = self.view dots.createCircle (group) dots.dot[4].x = 100 end ------------------------------------------------------------------------------------------ -- --==\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*[ENTER SCENE]\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*++-- -- ------------------------------------------------------------------------------------------ function scene:enterScene( event ) local group = self.view end ------------------------------------------------------------------------------------------ -- --==\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*[EXIT SCENE]\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*++-- -- ------------------------------------------------------------------------------------------ function scene:exitScene() local group = self.view end ------------------------------------------------------------------------------------------ -- --==\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*[DESTROY SCENE]\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*++-- -- ------------------------------------------------------------------------------------------ function scene:destroyScene( event ) local group = self.view end ---------------------------------------------------------------------------------- scene:addEventListener( "createScene", scene ) scene:addEventListener( "enterScene", scene ) scene:addEventListener( "exitScene", scene ) scene:addEventListener( "destroyScene", scene ) return scene
that’s it…
Look at line 13 of dots.lua. Do you see a reference to “dots”? Look at the rest of the function. Are you referencing “dots” or “dot”?
Rob
Okay…I changed that for this
local storyboard = require( "storyboard" ) local dots = require("dots") local scene = storyboard.newScene() ------------------------------------------------------------------------------------------ -- --==\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*[CREATE SCENE]\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*++-- -- ------------------------------------------------------------------------------------------ function scene:createScene( event ) local group = self.view dots.createCircle (group) dots.dots[4].x = 100 end ------------------------------------------------------------------------------------------ -- --==\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*[ENTER SCENE]\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*++-- -- ------------------------------------------------------------------------------------------ function scene:enterScene( event ) local group = self.view end ------------------------------------------------------------------------------------------ -- --==\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*[EXIT SCENE]\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*++-- -- ------------------------------------------------------------------------------------------ function scene:exitScene() local group = self.view end ------------------------------------------------------------------------------------------ -- --==\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*[DESTROY SCENE]\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*++-- -- ------------------------------------------------------------------------------------------ function scene:destroyScene( event ) local group = self.view end ---------------------------------------------------------------------------------- scene:addEventListener( "createScene", scene ) scene:addEventListener( "enterScene", scene ) scene:addEventListener( "exitScene", scene ) scene:addEventListener( "destroyScene", scene ) return scene
Same ERROR
File: dots.lua
Line: 13
Attempt to index field ‘dots’ (a nil value)
Can you post your dots.lua?
–dots.lua
-- dots.lua local M = { } M.dot = {} -- table of individual dots. function M.createCircle (group) local separacion = 40 local initialX = display.contentCenterX - 190 local initialY = display.contentCenterY local distance = 30 for i=1, 10 do M.dot[i] = display.newImageRect ("images/circleYes.png", 60, 60) group:insert( M.dots[i] ) M.dot[i].x = initialX + (separacion\*i) M.dot[i].y = initialY + distance\*1 M.dot[i]:scale(.5, .5) end end return M
guitar.lua
local storyboard = require( "storyboard" ) local dots = require("dots") local scene = storyboard.newScene() ------------------------------------------------------------------------------------------ -- --==\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*[CREATE SCENE]\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*++-- -- ------------------------------------------------------------------------------------------ function scene:createScene( event ) local group = self.view dots.createCircle (group) dots.dots[4].x = 100 end ------------------------------------------------------------------------------------------ -- --==\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*[ENTER SCENE]\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*++-- -- ------------------------------------------------------------------------------------------ function scene:enterScene( event ) local group = self.view end ------------------------------------------------------------------------------------------ -- --==\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*[EXIT SCENE]\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*++-- -- ------------------------------------------------------------------------------------------ function scene:exitScene() local group = self.view end ------------------------------------------------------------------------------------------ -- --==\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*[DESTROY SCENE]\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*++-- -- ------------------------------------------------------------------------------------------ function scene:destroyScene( event ) local group = self.view end ---------------------------------------------------------------------------------- scene:addEventListener( "createScene", scene ) scene:addEventListener( "enterScene", scene ) scene:addEventListener( "exitScene", scene ) scene:addEventListener( "destroyScene", scene ) return scene
this is all I have
Rob… Finally we got it…YES!!!
when I post this new one I notice the
M.dot = { }
I said , maybe here is the problem…
I change that for
M.dots = { }
and of course I change all the
dot for dots
and i works!!!
I/m posting here the final 2 files that DO WORK
for other people if they want to do the same
Thank you very much Rob for your help…
FINAL FILES
– dots.lua
-- dots.lua local M = { } M.dots = {} -- table of individual dots. function M.createCircle (group) local separacion = 40 local initialX = display.contentCenterX - 190 local initialY = display.contentCenterY local distance = 30 for i=1, 10 do M.dots[i] = display.newImageRect ("images/circleYes.png", 60, 60) group:insert( M.dots[i] ) M.dots[i].x = initialX + (separacion\*i) M.dots[i].y = initialY + distance\*1 M.dots[i]:scale(.5, .5) end end return M
guitar.lua
local storyboard = require( "storyboard" ) local dots = require("dots") local scene = storyboard.newScene() ------------------------------------------------------------------------------------------ -- --==\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*[CREATE SCENE]\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*++-- -- ------------------------------------------------------------------------------------------ function scene:createScene( event ) local group = self.view dots.createCircle (group) dots.dots[4].y = 149 end ------------------------------------------------------------------------------------------ -- --==\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*[ENTER SCENE]\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*++-- -- ------------------------------------------------------------------------------------------ function scene:enterScene( event ) local group = self.view end ------------------------------------------------------------------------------------------ -- --==\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*[EXIT SCENE]\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*++-- -- ------------------------------------------------------------------------------------------ function scene:exitScene() local group = self.view end ------------------------------------------------------------------------------------------ -- --==\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*[DESTROY SCENE]\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*++-- -- ------------------------------------------------------------------------------------------ function scene:destroyScene( event ) local group = self.view end ---------------------------------------------------------------------------------- scene:addEventListener( "createScene", scene ) scene:addEventListener( "enterScene", scene ) scene:addEventListener( "exitScene", scene ) scene:addEventListener( "destroyScene", scene ) return scene
I hope this helps someone else
Thanks Rob
How about changing the definition of myNewFunction to take a parameter:
function myNewFunction ( group )
line1 = …
group:insert(line1)
…
end
then when you call it:
myNewFuction( group )
assuming group is the name of the group you want to use.
Rob
I did not really understand how that works, but it works perfect!
thank you Rob.
–still waiting for my app to be approved in apple.
Okay Rob, please help me with this:
I have a dots.lua file
function dotsFunction (group) for i=1, 6 do b1 = display.newImageRect ("images/noteCircle.png", 60, 60) group:insert(b1) b1.x = 100 + (40\*i) b1.y = 100 b1:scale(.6, .6) end end
so I create 6 images, circles – 1 to 6
in my guitar.lua file I require the dots.lua
and I have this function
local function reChord () local thisIsRe = "D" if thisIsRe == "D" then b1.y = 50 print("Re") end end dotsFunction(group) reChord()
it works perfect, the last circle (number6) is Up and all five are aligned.
I have – b1.y = 50
but I want the circle number 3 to be 50, not the circle number 6
I have for i=1, 6
so I want to move only 3, or 2
how do I distinguish them
i think is inside the if thisIsRe == “D” then but instead of b1.y – I can not put b3.y
so how do I do that?
thanks
You probably need to store them in a table/array so that you can reference each dot indepenendantly
Okay…would you help me understand it…
I use this Method for a table
local colorTable = { [1] = "blue", [2] = "red", [3] = "yellow", [4] = "green", [5] = "purple" } print( colorTable[3] ) -- output: "yellow"
so how would that work…
local dotsFunction = { [1] = "dot1", [2] = "dot2", [3] = "dot3", [4] = "dot4", [5] = "dot5" -- and so on until I get 40 dots... } print( dotsFunction[3] ) -- output: "yellow"
--------- then here
local function reChord () if pmThisChordIs == "Em" then dotsFunction[4].alpha = .5 -- something like that .... b1.alpha = .5 print("Re") end end dotsFunction(group) reChord()
but how do I create them?
for i=1, #dotsFunction do b1 = display.newImageRect ("images/noteCircle.png", 60, 60) group:insert(b1) b1.x = initialX + (separacion\*i) b1.y = initialY + distance\*1 b1:scale(.5, .5) end
as you can see I’m kind of confuse…
local dots = {} for i=1, #dotsFunction do dots[i] = display.newImageRect ("images/noteCircle.png", 60, 60) group:insert(dots[i]) dots[i].x = initialX + (separacion\*i) dots[i].y = initialY + distance\*1 dots[i]:scale(.5, .5) end
or something like that. Replace the references to b1 with dots[] and the index to the dot you’re interested in.
Rob
I create a function newDots (group) with the group
function newDots (group) local dots = {} for i=1, 10 do dots[i] = display.newImageRect ("images/circleYes.png", 60, 60) group:insert(dots[i]) dots[i].x = initialX + (separacion\*i) dots[i].y = initialY + distance\*1 dots[i]:scale(.5, .5) end end
and when I call the function it works perfect
newDots(group) dots[4].y = 50
but then I move the .y of the dots[4] and --ERROR
I think I’m very close Rob
thanks for your time and help…
I’d need to see more of your code and the whole stack trace
Rob
okay…
in dots.lua
function newDots (group) local dots = {} local separacion = 40 local initialX = display.contentCenterX - 190 local initialY = display.contentCenterY - 110 local distance = 30 for i=1, 10 do dots[i] = display.newImageRect ("images/circleYes.png", 60, 60) group:insert(dots[i]) dots[i].x = initialX + (separacion\*i) dots[i].y = initialY + distance\*1 dots[i]:scale(.5, .5) end end
in guitar.lua
newDots(group)
i require the dots.lua, and
I just call the function… it works perfect, I see 10 circles
now… How do write the code to make the circle no. 5 = alpha = .5
in other words, how do I acces each – dots[i] – individually?
dots[4].alpha=.5 – it doesn’t work
i hope this helps
I suspect the problem is that you have made dots local to the function newDots() which means you can’t access it outside of that function. I would declare:
local dots = {}
at the top of your module and take the local off inside the function.
Rob
I try this
local dots = {} function newDots (group) local separacion = 40 local initialX = display.contentCenterX - 190 local initialY = display.contentCenterY - 110 local distance = 30 for i=1, 10 do dots[i] = display.newImageRect ("images/circleYes.png", 60, 60) group:insert(dots[i]) dots[i].x = initialX + (separacion\*i) dots[i].y = initialY + distance\*1 dots[i]:scale(.5, .5) end end
the table dots = { } – is outside the newDots function
then on guitar.lua I do this
newDots(group) dots[4].alpha=.5
still it does not work!
File: guitar.lua
Line: 154
Attempt to index upvalue ‘dots’ (a boolean value)