About Monkey 2 › Forums › Monkey 2 Programming Help › New Vec2f not working inside New Constructor ?
Tagged: Vec2f
This topic contains 4 replies, has 4 voices, and was last updated by
gcmartijn 2 years, 8 months ago.
-
AuthorPosts
-
August 8, 2016 at 7:15 pm #2861
I’m trying to convert a Monkey code to MX2 but, I get a strange error.
In the old Monkey code I was using a Vector class, but I thought this is overkill so i’m was trying the Vec2f instead.What I have done is strip all the code to make it readable.
When I run this code the program hangs at the point that inside the Player Constructor a method Move(x,y) is creating a New Vec2fIn other words, I can’t create a Vec2f inside a method called by a Method New
Now I’m thinking or its a bug, or its because its a struct thing ?
Maybe Vec2f is not a replacement for the Vector class i’m using ?Monkey123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566Namespace myapp#Import "<std>"#Import "<mojo>"Using std..Using mojo..Class MyWindow Extends WindowMethod New()Local FrameSetCollection:StringMap<FrameSet> = New StringMap<FrameSet>()Local player:Player = New Player(FrameSetCollection, "Bla", 200, 300)EndMethod OnRender( canvas:Canvas ) Overridecanvas.DrawText( "Hello World",Width/2,Height/2,.5,.5 )EndEndFunction Main()New AppInstanceNew MyWindowApp.Run()EndClass FrameSetField Position:= New Vec2fMethod Move:Void(_mx:Float, _my:Float)' Print _mx' Print _my' HERE IS THE ERROR, CREATING NEW VEC2F''' Position=New Vec2f - CRASHPosition = New Vec2f(_mx,_my)EndEnd ClassClass SpriteField FrameSetCollection:StringMap<FrameSet>Field FrameSetColKey:StringMethod New(_FrameSetCollection:StringMap<FrameSet>,_FrameSetColKey:String)FrameSetCollection = _FrameSetCollectionFrameSetColKey = _FrameSetColKeyEndEnd ClassClass Player Extends SpriteMethod New(_FrameSetCollection:StringMap<FrameSet>,_FrameSetColKey:String,_initX:Float,_initY:Float)Super.New(_FrameSetCollection,_FrameSetColKey)_FrameSetCollection.Get(_FrameSetColKey).Move(_initX,_initY)EndEnd ClassAugust 8, 2016 at 7:21 pm #2862If you look over at your debug window you will see Self is null so I think your issue has nothing to do with Vec2f.
Monkey2 does not treat null method calls as an error in debug mode.
August 8, 2016 at 10:44 pm #2891Think you’re just forgetting to add a new FrameSet to the map. Interesting that the method can be called on a null object though.
Monkey12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667Namespace myapp#Import "<std>"#Import "<mojo>"Using std..Using mojo..Class MyWindow Extends WindowMethod New()Local FrameSetCollection:StringMap<FrameSet> = New StringMap<FrameSet>()Local player:Player = New Player(FrameSetCollection, "Bla", 200, 300)EndMethod OnRender( canvas:Canvas ) Overridecanvas.DrawText( "Hello World",Width/2,Height/2,.5,.5 )EndEndFunction Main()New AppInstanceNew MyWindowApp.Run()EndClass FrameSetField Position:= New Vec2fMethod Move:Void(_mx:Float, _my:Float)' Print _mx' Print _my' HERE IS THE ERROR, CREATING NEW VEC2F''' Position=New Vec2f - CRASHPosition = New Vec2f(_mx,_my)EndEnd ClassClass SpriteField FrameSetCollection:StringMap<FrameSet>Field FrameSetColKey:StringMethod New(_FrameSetCollection:StringMap<FrameSet>,_FrameSetColKey:String)FrameSetCollection = _FrameSetCollectionFrameSetColKey = _FrameSetColKeyFrameSetCollection.Add(FrameSetColKey, New FrameSet) '<<<<<EndEnd ClassClass Player Extends SpriteMethod New(_FrameSetCollection:StringMap<FrameSet>,_FrameSetColKey:String,_initX:Float,_initY:Float)Super.New(_FrameSetCollection,_FrameSetColKey)_FrameSetCollection.Get(_FrameSetColKey).Move(_initX,_initY)EndEnd ClassAugust 9, 2016 at 12:25 am #2892Interesting that the method can be called on a null object though.
Yeah, I might yet change this, but mx2cc itself currently depends on this behaviour so it wont be for a while yet.
August 9, 2016 at 5:33 am #2893 -
AuthorPosts
You must be logged in to reply to this topic.