Monkey Documentation

Keyword Method

Declares the beginning of a class method.

Syntax

Method Identifier: ReturnType ( Parameters ) [ Property ] [ Abstract ] [ Final ]~n Statements...
End [ Method ]

Description

The Method keyword begins the declaration of a class method.

Please see the Methods section of the monkey language reference for more information on methods.

See also

End | Class | Property | Abstract | Final
Language reference (Classes)
Language reference (Methods)

Examples

An example of methods as statements.

Class GameObject

    Field x:Float
    Field y:Float

    Method PrintX ()
        Print x
    End

    Method PrintY ()
        Print y
    End

End

Local g:GameObject = New GameObject

p.x = 100
p.y = 200

' Accessing method...

p.PrintX
p.PrintY

Strict mode version of above GameObject class. (Note use of Void return type.)

Class GameObject

    Field x:Float
    Field y:Float

    Method PrintX:Void ()
        Print x
    End

    Method PrintY:Void ()
        Print y
    End

End

Method returning value of Float type.

Class GameObject

    Method AddFloats:Float (value1:Floatvalue2:Float)
        Return value1 + value2
    End

End

Local g:GameObject = New GameObject

' Accessing method...

Print g.AddFloats (1.52.0)