Class list

Ferret3D

New member
Joined
Aug 13, 2017
Messages
88
I need a list of mi puzzle piece class.
How do i create a list of a class?
 

dawlane

Well-known member
CX Code Contributor
Joined
Jun 21, 2017
Messages
840
Use:
Code:
Local list:= New List<MyObject> ' Short hand way
Local list:List<MyObject> = New List<MyObject> ' Long way

Here is an example. Use the C++Tool target to compile.
Code:
Strict

Class MyObject
    Field str:String
 
    Method New(str:String = "")
        Self.str = str
    End Method
 
    Method Item:String()
        Return Self.str
    End Method
 
End Class


Function Main:Int()
    'Local list:= New List<MyObject> ' Short hand way
     Local list:List<MyObject> = New List<MyObject> ' Long way
 
    ' Add some items to the list
    For Local i:Int = 1 To 10
        list.AddLast(New MyObject("Item: " + i))
    Next
 
    ' Retrieve the items
    For Local i:MyObject = Eachin list
        Print i.Item()
    Next
 
    Return 0
End Function
 
Last edited:

Phil7

Administrator
CX Code Contributor
3rd Party Tool Dev
Joined
Jun 26, 2017
Messages
636
why the c++ tool to compile? What is it exactly for?
 

dawlane

Well-known member
CX Code Contributor
Joined
Jun 21, 2017
Messages
840
The C++ Tool (formally stdcpp) is for creating simple command line tools. It's pretty much useless for anything other than testing out simple code.
 
Last edited:

dawlane

Well-known member
CX Code Contributor
Joined
Jun 21, 2017
Messages
840
Lol, Trans and MakeDocs are compiled with it. So it isn't really useless.
That's all it's about good for. If you want a little more oomph; then the os module needs to be expanded for better system function access. The number of times I wish that Mark had implemented getting stdout and stderror when using the Execute function, or a high resolution timer.
 
Last edited:

Gerry Quinn

Active member
Tutorial Author
Joined
Jun 24, 2017
Messages
151
What am I missing here? Shouldn't that run fine in HTML5 or whatever you want?
 

MikeHart

Administrator
Joined
Jun 19, 2017
Messages
3,135
What am I missing here? Shouldn't that run fine in HTML5 or whatever you want?

All of CX targets (besides the C++ tool one) depend on the App class (which you have to extend from) and so need at least an OnRender method to display something.
 

dawlane

Well-known member
CX Code Contributor
Joined
Jun 21, 2017
Messages
840
What am I missing here? Shouldn't that run fine in HTML5 or whatever you want?
It should still compile and run fine in the GLFW/HTML game. The only difference will be the size of the compiled code, don't forget that you would be pulling in additional libraries that are not needed and add additional compile time for what is basically a simple example.

All of CX targets (besides the C++ tool one) depend on the App class (which you have to extend from) and so need at least an OnRender method to display something.
Only if you include any of the Mojo frameworks.
 

Ferret3D

New member
Joined
Aug 13, 2017
Messages
88
Use:
Code:
Local list:= New List<MyObject> ' Short hand way
Local list:List<MyObject> = New List<MyObject> ' Long way

Here is an example. Use the C++Tool target to compile.
Code:
Strict

Class MyObject
    Field str:String
 
    Method New(str:String = "")
        Self.str = str
    End Method
 
    Method Item:String()
        Return Self.str
    End Method
 
End Class


Function Main:Int()
    'Local list:= New List<MyObject> ' Short hand way
     Local list:List<MyObject> = New List<MyObject> ' Long way
 
    ' Add some items to the list
    For Local i:Int = 1 To 10
        list.AddLast(New MyObject("Item: " + i))
    Next
 
    ' Retrieve the items
    For Local i:MyObject = Eachin list
        Print i.Item()
    Next
 
    Return 0
End Function

Thank you!
 
Top Bottom