About Monkey 2 › Forums › General Programming Discussion › fantomX2 for Monkey2
Tagged: fantomX2
This topic contains 12 replies, has 5 voices, and was last updated by
MikeHart 2 years, 4 months ago.
-
AuthorPosts
-
August 4, 2016 at 8:21 am #2734
Just to let you know, I started porting fantomX to Monkey2. It is progressing well but some more work to do as Monkey2 is missing some features from Monkey X I guess and I need to replace them.
For an example, it looks like you can resize (by using Slice) or initialise an aray only downwards. Or does anyone know how to extend an aray dynamically?
August 4, 2016 at 9:48 am #2735You might want to look at stacks which by my understanding are basically arrays that you can resize easily.
August 4, 2016 at 10:23 am #2737Thanks Peter, that was my plan. But still need to have a look into them.
August 4, 2016 at 11:04 am #2741You could write a little “ResizeArray()” function that uses generics and the array CopyTo() method. Rough example:
[/crayon]Monkey123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293[crayon-5cb9caca232ce465067451 inline="true" ]#include "<std>"Using std..'***Function ResizeArray<T>:T[](arr:T[], length:ULong)Local tmp := New T[length]Local count := arr.LengthIf count > tmp.Length Then count = tmp.Lengtharr.CopyTo(tmp, 0, 0, count)Return tmpEnd'***Function Main:Void()'--- Primitive typeLocal arr:= New Int[](0, 1, 2, 3, 4)arr = ResizeArray<Int>(arr, arr.Length * 2)Print "~n--Primitive type array after resize (new element values = 0)--"For Local i := 0 Until arr.LengthPrint i + ": " + arr[i]Next'--- ClassLocal arr2 := New Obj[5]Obj.InitArray(arr2)Print "~n--Class object array Before Resize--"Obj.PrintArray(arr2)arr2 = ResizeArray<Obj>(arr2, arr2.Length * 2)Print "~n--Class object array After Resize --"Print "--New elements have an incremental id value --"Obj.InitArray(arr2)Obj.PrintArray(arr2)End'***Class ObjPrivateGlobal IdValue:UInt = 0Field _id:UIntPublicMethod New()_id = IdValueIdValue += 1End'---Property Id:UInt()Return _idEndMethod ToString:String()Return String(_id)End'---Function InitArray:Void(arr:Obj[])If Not arr Then ReturnFor Local i:= 0 Until arr.LengthIf arr[i] = Null Then arr[i] = New ObjNextEndFunction PrintArray:Void(arr:Obj[])If Not arr Then ReturnFor Local i:= 0 Until arr.LengthIf arr[i] <> Null Then Print i + ": " + arr[i].ToString()NextEndEndEDIT: I should add that the above basically replicates Monkey 1 behavior – slicing and array.Resize() create new arrays rather than truly contracting/extending existing arrays.
August 4, 2016 at 1:56 pm #2752Thanks for the code sample. If I don’t get Stacks running like I want to then I will try your code.
August 5, 2016 at 7:05 pm #2803Pretty much sums it up :
August 6, 2016 at 8:36 am #2820LOL, thanks Neuro!
August 10, 2016 at 4:03 pm #2922Just glad to see you back!
August 11, 2016 at 4:40 am #2929I would have posted on the MX forum before but for some odd reason i can’t.
August 12, 2016 at 10:29 am #2946And now I can. Mark fixed my User account.
September 27, 2016 at 10:05 am #4114Hi Mike,
Are you still continuing with this one? I noticed you took down the fantomX website so was curious if you’re still going to port your fantom framework over to MX2? (i sincerely hope you do!)
October 20, 2016 at 8:41 am #4543Yes, I will continue with it.
November 23, 2016 at 9:08 pm #5395 -
AuthorPosts
You must be logged in to reply to this topic.
