• Dear Cerberus X User!

    As we prepare to transition the forum ownership from Mike to Phil (TripleHead GmbH), we need your explicit consent to transfer your user data in accordance with our amended Terms and Rules in order to be compliant with data protection laws.

    Important: If you accept the amended Terms and Rules, you agree to the transfer of your user data to the future forum owner!

    Please read the new Terms and Rules below, check the box to agree, and click "Accept" to continue enjoying your Cerberus X Forum experience. The deadline for consent is April 5, 2024.

    Do not accept the amended Terms and Rules if you do not wish your personal data to be transferred to the future forum owner!

    Accepting ensures:

    - Continued access to your account with a short break for the actual transfer.

    - Retention of your data under the same terms.

    Without consent:

    - You don't have further access to your forum user account.

    - Your account and personal data will be deleted after April 5, 2024.

    - Public posts remain, but usernames indicating real identity will be anonymized. If you disagree with a fictitious name you have the option to contact us so we can find a name that is acceptable to you.

    We hope to keep you in our community and see you on the forum soon!

    All the best

    Your Cerberus X Team

How do you declare 2d lists

john2367

New member
Joined
Feb 19, 2019
Messages
10
How do you actually declare 2d lists in cerberus x?
Cerberus:
Field 2dListForAnObject:List<List <Object>>
Is the code above the right syntax?
 
2D list? Do you mean a 2D array?

If the later, then this should show it well.
Cerberus:
Strict

Import mojo

'-----------------------------------------------------------------
Class myClass Extends App
    ' Declare an 2D array
    Field mA:Int[][]
    '-----------------------------------------------------------------
    Method OnCreate:Int()
        SetUpdateRate 60
        ' Initialze the first dimension
        mA = New Int[10][]
        For Local x:Int = 0 To mA.Length()-1
            ' Initialize the second dimension
            mA[x]= New Int[15]
            For Local y:= 0 To mA[x].Length()-1
                ' Fill values into your array
                mA[x][y] = x*y
            Next
        Next
        Return 0
    End
    '-----------------------------------------------------------------
    Method OnRender:Int()
        Cls 155,0,0
        For Local x:Int = 0 To mA.Length()-1
            For Local y:= 0 To mA[x].Length()-1
                DrawText mA[x][y], x*25+150, y*25+50, .5, .5
            Next
        Next
        Return 0
    End
End

'-----------------------------------------------------------------
Function Main:Int()
    New myClass
    Return 0
End
 
Last edited:
Variable names must start with a letter or an underscore character. So instead of "2dListForAnObject" write something like "my2dList". Remember that this just declares just a variable – the value is still Null. In order to create a list object you can write something like this:
Cerberus:
Field  my2dList := New List<List<Object>>
To add a list to your list write:
Cerberus:
my2dList.AddLast(New List<Object>)
Btw, for what do you need this 2d list structure? Depending on what you want to do some other data structure might be a better choice.
 
Back
Top Bottom