What is the different between the dot and semicolon in ...

Table Listener 1

local object = display.newImage( “ball.png” )

object.id = “ball object”

local function onObjectTouch( self, event )

    if event.phase == “began” then

        print( "Touch event began on: " … self.id )

    end

    return true

end 

object.touch = onObjectTouch

object:addEventListener( “touch”, object )

Table Listener 2

local object = display.newImage( “ball.png” )

object.id = “ball object”

function object:touch ( event )

    if event.phase == “began” then

        print( "Touch event began on: " … self.id )

    end

    return true

end 

object:addEventListener( “touch”, object )

What is the different between the dot and semicolon in  object.touch  and  object:touch

Can someone pls explain to me

thank

When you use the object:method(paramA), is the same as calling library.method(object, paramA). I.e., the “:” assumes that you are passing the own object as the first parameter because that function will change that object in some way.

Example:

object:removeSelf()   is the same as  display.remove(object)


From the docs (http://docs.coronalabs.com/guide/start/helloWorld/index.html)

About “Colon” Notation

In addition to the  dot  notation explained above, let’s examine the  colon  notation.

This notation is called an  object method. Typically this method modifies the variable/object before the colon. In this tutorial, setTextColor( 255, 0, 0 ), following the colon, tells Corona that you want to change the color of myTextObject, specified before the colon.

Here is another source of info on dot vs colon: http://developer.coronalabs.com/content/introduction#Dot_vs_Colon

I’ve read it, thank for the help

Hi all,

Just as a side note, the document that @roaminggamer refers to is quite old, and the links there shouldn’t be referenced either. Many of those resources have been replaced by newer guides, and more are coming soon:

http://docs.coronalabs.com/guide/index.html

So, please use this URL and try to avoid that other sub-domain entirely. Some of those pages still pop up in a Google search, but we’re working to replace them and get the old versions un-indexed in the search engines.

Thanks,

Brent

When you use the object:method(paramA), is the same as calling library.method(object, paramA). I.e., the “:” assumes that you are passing the own object as the first parameter because that function will change that object in some way.

Example:

object:removeSelf()   is the same as  display.remove(object)


From the docs (http://docs.coronalabs.com/guide/start/helloWorld/index.html)

About “Colon” Notation

In addition to the  dot  notation explained above, let’s examine the  colon  notation.

This notation is called an  object method. Typically this method modifies the variable/object before the colon. In this tutorial, setTextColor( 255, 0, 0 ), following the colon, tells Corona that you want to change the color of myTextObject, specified before the colon.

Here is another source of info on dot vs colon: http://developer.coronalabs.com/content/introduction#Dot_vs_Colon

I’ve read it, thank for the help

Hi all,

Just as a side note, the document that @roaminggamer refers to is quite old, and the links there shouldn’t be referenced either. Many of those resources have been replaced by newer guides, and more are coming soon:

http://docs.coronalabs.com/guide/index.html

So, please use this URL and try to avoid that other sub-domain entirely. Some of those pages still pop up in a Google search, but we’re working to replace them and get the old versions un-indexed in the search engines.

Thanks,

Brent