Tuesday, February 24, 2015

Monkey-X - Beginners - Chaining and Classes and Self - code example

Here a example of how to chain commands in Monkey. This by returning Self.

Code below :

Import mojo

Class test
    Field x:Int,y:Int
    Method incx:test(val:Int)
        If x>1000 Then x=0
        Return Self
    End Method
    Method incy:test(val:Int)
        If y>1000 Then y=0
        Return Self
    End Method
    Method drawvalue()
        DrawText "x:"+x+" y:"+y,0,15
    End Method
End Class

Global t:test = New test

Class MyGame Extends App

    Method OnCreate()
    End Method
    Method OnUpdate()
    End Method
    Method OnRender()
        Cls 0,0,0 
        SetColor 255,255,255
        DrawText "Chaining example.",0,0
    End Method
End Class

Function Main()
    New MyGame()
End Function

No comments:

Post a Comment