Monkey List to BMX List

BlitzMax Forums/BlitzMax Programming/Monkey List to BMX List

RustyKristi(Posted 2016) [#1]
Unable to use MonkeyMax, I have the following List that I need to convert to BMX from Monkey code:

Class Parts
  Field x:Float
  Field y:Float
  Field z:Float
End Class

Class Members
  Field JointsList:List<Parts>
  Method New()
    JointsList = New List<Parts>()
  End Method
End Class



therevills(Posted 2016) [#2]
This should be it:

Type Parts
  Field x:Float
  Field y:Float
  Field z:Float
EndType

Type Members
  Field jointsList:TList
  Method New()
    jointsList = New TList
  EndMethod
EndType


Full example:



RustyKristi(Posted 2016) [#3]
Thanks therevills. I will try this out! :)


RustyKristi(Posted 2016) [#4]
One question, so the <Parts> can be ingored in Blitzmax?


Derron(Posted 2016) [#5]
Yee.

Tlist is more generic. It just stores "object"s.


Bye
Ron


therevills(Posted 2016) [#6]
The <Parts> are part of "Generics" within MX, it forces the list to only contain objects of that type, eg JointsList = New List<Parts>() can only hold Parts objects.

A TList as Ron has said is more generic... it can hold any type of object, for example you can add different objects and Strings to the same list, but if you access them you will need to cast to the assigned variable's type.


Derron(Posted 2016) [#7]
You only need to cast them, if you access them via "ValueAtIndex()".

For local bl:onlyThisType = EachIn list
...
Next


Only iterates over list entries of type "onlyThisType" (or extending from it).


bye
Ron


therevills(Posted 2016) [#8]
Yeah I forgot that Eachin would only return the object type specified.. Heres an example of what Ron is saying:


Of course you would want to be a bit smarter and use inheritance:



RustyKristi(Posted 2016) [#9]
Thanks guys, I have to checkout what you have given here and hopefully it would be simple enough with that <> and List part that is throwing this issue.

So is Class just equivalent to BMX Type?


therevills(Posted 2016) [#10]
So is Class just equivalent to BMX Type?

Yes... but within BMX you cant use interfaces without doing a kludge.