Basic Shape-Matching and Storyboard API

Hello! I am trying to integrate a basic shape-matching in storyboard. I’ve used this as a reference http://www.coronalabs.com/blog/2013/01/29/basic-shape-matching-app/.

This is my scene1.lua file

--------------------------------------------------------------------------------- -- -- scene1.lua -- --------------------------------------------------------------------------------- local storyboard = require( "storyboard" ) local scene = storyboard.newScene() local MultiTouch = require("dmc\_multitouch") --------------------------------------------------------------------------------- -- BEGINNING OF YOUR IMPLEMENTATION --------------------------------------------------------------------------------- local background local dispObj\_5 local countries193 MultiTouch.activate(countries193, "move", "single"); local countries193PosX = 0; local countries193PosY = 0; local function countries193Drag (event) local t = event.target if event.phase == "moved" then countries193PosX = countries193.x - dispObj\_5.x; countries193PosY = countries193.y - dispObj\_5.y; if (countries193PosX \< 0) then countries193PosX = countries193PosX \* -1; end if (countries193PosY \< 0) then countries193PosY = countries193PosY \* -1; end if (countries193PosX \<= 50) and (countries193PosY \<= 50) then countries193.x = dispObj\_5.x; countries193.y = dispObj\_5.y; end elseif event.phase == "ended" then if (countries193PosX \<= 50) and (countries193PosY \<= 50) then countries193.x = dispObj\_5.x; countries193.y = dispObj\_5.y; -- If you'd like to be able to move the square again, comment out the line below MultiTouch.deactivate(countries193); end end return true; end -- Called when the scene's view does not exist: function scene:createScene( event ) local screenGroup = self.view background = display.newImage( "background.png" ) screenGroup:insert( background ) countries193 = display.newImageRect( "level23\_193.png", 55, 40 ) countries193.x = 75 countries193.y = 275 screenGroup:insert( countries193 ) countries193:addEventListener(MultiTouch.MULTITOUCH\_EVENT, countries193Drag); dispObj\_5 = display.newImageRect( "level23\_input.png", 60, 36 ) dispObj\_5.x = 242 dispObj\_5.y = 201 screenGroup:insert( dispObj\_5 ) end -- Called immediately after scene has moved onscreen: function scene:enterScene( event ) storyboard.printMemUsage() -- remove previous scene's view storyboard.removeAll() -- Update Lua memory text display end -- Called when scene is about to move offscreen: function scene:exitScene( event ) end -- Called prior to the removal of scene's "view" (display group) function scene:destroyScene( event ) end --------------------------------------------------------------------------------- -- END OF YOUR IMPLEMENTATION --------------------------------------------------------------------------------- -- "createScene" event is dispatched if scene's view does not exist scene:addEventListener( "createScene", scene ) -- "enterScene" event is dispatched whenever scene transition has finished scene:addEventListener( "enterScene", scene ) -- "exitScene" event is dispatched before next scene's transition begins scene:addEventListener( "exitScene", scene ) -- "destroyScene" event is dispatched before view is unloaded, which can be -- automatically unloaded in low memory situations, or explicitly via a call to -- storyboard.purgeScene() or storyboard.removeScene(). scene:addEventListener( "destroyScene", scene ) --------------------------------------------------------------------------------- return scene

The error i’m getting:

Runtime error: dmc\_touchmanage.lua:133: table index is nil &nbsp;

I’ve added the archieve touch.lua if someone wants to view the full code source.

I appreciate any help!

Thank you.

I don’t know what this dmc_touchmanage.lua is, but line 133 its looking for an index to a table that is nil.  Perhaps you could look at that code, see what’s expected to be passed to it and make sure you’re passing the right thing.

Hello! http://www.coronalabs.com/blog/2013/01/29/basic-shape-matching-app/ in the example provided in the post (https://www.dropbox.com/s/tr17upti8eeq7c6/SnapShapes.zip) there are three lua files which are required.

dmc_gesture.lua

dmc_multitouch.lua

dmc_touchmanager.lua

It’s dmc_touchmanage r. lua, sorry, my fault https://github.com/dmccuskey/DMC-Corona-Library/blob/master/dmc_touchmanager.lua)

It’s hard for us to provide support for 3rd party libraries but I’m guessing that this line:

MultiTouch.activate(countries193, “move”, “single”);

should probably be in your enterScene() function.  You are executing that line before countries193 is initialized (It’s currently nil).  Try putting that line somewhere in your enterScene()  and if it has a matching .deactivate() put it in your exitScene().

Thank you for your response. You were right, MultiTouch.activate should have been inside the enterScene() function.

Now seems to work correctly; however, the simulator displays two squares (a blue and a red one).

http://www.youtube.com/watch?v=KzXskeMJmuA

Anyone has any idea how to “hide” the squares?

I know Corona can’t provide support for 3rd party tools. I posted it hoping that someone encountered the same problem while using storyboard with basic-shape matching. Again, thanks for your support, Rob.

LATER EDIT: The problem was in dmc_multitouch.lua between lines 558 and 580.

if DEBUG then &nbsp;&nbsp;&nbsp;&nbsp;local obj &nbsp;&nbsp;&nbsp;&nbsp;-- blue spot over center of main object &nbsp;&nbsp;&nbsp;&nbsp;obj = display.newRect( 0, 0, 16, 16 ) &nbsp;&nbsp;&nbsp;&nbsp;obj:setFillColor(0,0,255) &nbsp;&nbsp;&nbsp;&nbsp;obj:toFront() &nbsp;&nbsp;&nbsp;&nbsp;debugObjs["objCenter"] = obj &nbsp;&nbsp;&nbsp;&nbsp;-- green spot over midpoint center &nbsp;&nbsp;&nbsp;&nbsp;obj = display.newRect( 0, 0, 10, 10 ) &nbsp;&nbsp;&nbsp;&nbsp;obj:setFillColor(0,255,0) &nbsp;&nbsp;&nbsp;&nbsp;obj:toFront() &nbsp;&nbsp;&nbsp;&nbsp;debugObjs["touchCenter"] = obj &nbsp;&nbsp;&nbsp;&nbsp;-- red spot over calculated center &nbsp;&nbsp;&nbsp;&nbsp;obj = display.newRect( 0, 0, 10, 10 ) &nbsp;&nbsp;&nbsp;&nbsp;obj:setFillColor(255,0,0) &nbsp;&nbsp;&nbsp;&nbsp;obj:toFront() &nbsp;&nbsp;&nbsp;&nbsp;debugObjs["calcCenter"] = obj end &nbsp;

Just set transparency to rectangles and it’s all solved:)

if DEBUG then local obj -- blue spot over center of main object obj = display.newRect( 0, 0, 16, 16 ) obj:setFillColor(0,0,255,0) obj:toFront() debugObjs["objCenter"] = obj -- green spot over midpoint center obj = display.newRect( 0, 0, 10, 10 ) obj:setFillColor(0,255,0,0) obj:toFront() debugObjs["touchCenter"] = obj -- red spot over calculated center obj = display.newRect( 0, 0, 10, 10 ) obj:setFillColor(255,0,0,0) obj:toFront() debugObjs["calcCenter"] = obj end

Hey Stefan, glad you got it working. Sorry, I just got back into town from a business trip and couldn’t look into the issue.

I don’t know what this dmc_touchmanage.lua is, but line 133 its looking for an index to a table that is nil.  Perhaps you could look at that code, see what’s expected to be passed to it and make sure you’re passing the right thing.

Hello! http://www.coronalabs.com/blog/2013/01/29/basic-shape-matching-app/ in the example provided in the post (https://www.dropbox.com/s/tr17upti8eeq7c6/SnapShapes.zip) there are three lua files which are required.

dmc_gesture.lua

dmc_multitouch.lua

dmc_touchmanager.lua

It’s dmc_touchmanage r. lua, sorry, my fault https://github.com/dmccuskey/DMC-Corona-Library/blob/master/dmc_touchmanager.lua)

It’s hard for us to provide support for 3rd party libraries but I’m guessing that this line:

MultiTouch.activate(countries193, “move”, “single”);

should probably be in your enterScene() function.  You are executing that line before countries193 is initialized (It’s currently nil).  Try putting that line somewhere in your enterScene()  and if it has a matching .deactivate() put it in your exitScene().

Thank you for your response. You were right, MultiTouch.activate should have been inside the enterScene() function.

Now seems to work correctly; however, the simulator displays two squares (a blue and a red one).

http://www.youtube.com/watch?v=KzXskeMJmuA

Anyone has any idea how to “hide” the squares?

I know Corona can’t provide support for 3rd party tools. I posted it hoping that someone encountered the same problem while using storyboard with basic-shape matching. Again, thanks for your support, Rob.

LATER EDIT: The problem was in dmc_multitouch.lua between lines 558 and 580.

if DEBUG then &nbsp;&nbsp;&nbsp;&nbsp;local obj &nbsp;&nbsp;&nbsp;&nbsp;-- blue spot over center of main object &nbsp;&nbsp;&nbsp;&nbsp;obj = display.newRect( 0, 0, 16, 16 ) &nbsp;&nbsp;&nbsp;&nbsp;obj:setFillColor(0,0,255) &nbsp;&nbsp;&nbsp;&nbsp;obj:toFront() &nbsp;&nbsp;&nbsp;&nbsp;debugObjs["objCenter"] = obj &nbsp;&nbsp;&nbsp;&nbsp;-- green spot over midpoint center &nbsp;&nbsp;&nbsp;&nbsp;obj = display.newRect( 0, 0, 10, 10 ) &nbsp;&nbsp;&nbsp;&nbsp;obj:setFillColor(0,255,0) &nbsp;&nbsp;&nbsp;&nbsp;obj:toFront() &nbsp;&nbsp;&nbsp;&nbsp;debugObjs["touchCenter"] = obj &nbsp;&nbsp;&nbsp;&nbsp;-- red spot over calculated center &nbsp;&nbsp;&nbsp;&nbsp;obj = display.newRect( 0, 0, 10, 10 ) &nbsp;&nbsp;&nbsp;&nbsp;obj:setFillColor(255,0,0) &nbsp;&nbsp;&nbsp;&nbsp;obj:toFront() &nbsp;&nbsp;&nbsp;&nbsp;debugObjs["calcCenter"] = obj end &nbsp;

Just set transparency to rectangles and it’s all solved:)

if DEBUG then local obj -- blue spot over center of main object obj = display.newRect( 0, 0, 16, 16 ) obj:setFillColor(0,0,255,0) obj:toFront() debugObjs["objCenter"] = obj -- green spot over midpoint center obj = display.newRect( 0, 0, 10, 10 ) obj:setFillColor(0,255,0,0) obj:toFront() debugObjs["touchCenter"] = obj -- red spot over calculated center obj = display.newRect( 0, 0, 10, 10 ) obj:setFillColor(255,0,0,0) obj:toFront() debugObjs["calcCenter"] = obj end

Hey Stefan, glad you got it working. Sorry, I just got back into town from a business trip and couldn’t look into the issue.

Sir CrunchyApps, I have the same error. How did you fix that error?

Runtime error:

dmc_touchmanage.lua:133: table index is nil
 

Sir CrunchyApps, I have the same error. How did you fix that error?

Runtime error:

dmc_touchmanage.lua:133: table index is nil