Records
Monkey Forums/Monkey Programming/Records
| ||
Does Monkey support records? In Delphi, I can use something like this : TRect=record Left:Integer Top:Integer Right:Integer Bottom:Integer End And I can have a variable ARect:TRect and I set and get it's values when I need! I tryed this on Monkey : Class TRect Global Left:Int Global Top:Int Global Right:Int Global Bottom:Int End I have this : Class TSprite Method getRect:TRect() Local aRect:TRect aRect.Left=Self.x-Pattern.Width/2 aRect.Right=Self.x+Pattern.Width/2 aRect.Top=Self.y-Pattern.Height/2 aRect.Bottom=Self.y+Pattern.Height/2 Return aRect End Well... it almost works! But if I call getRect from two different sprites at the same time, both get the same value. I can change TRect properties from Global to Field, and instantiate it everytime I use, but what will happens if I call something like this : If OverlapRect(ASprite1.getRect(),aSprite2.getRect()). The objects of this classess will stay in memory or will be freed? |
| ||
All class instances stay always in memory, because Monkey does not a have a class destructor or Delete command, but only a New command to reserve memory for an instance of a class. So using fields is the correct way. |
| ||
Will this be fixed in the future? Destroy instances of classes is a must have. |
| ||
The objects of this classess will stay in memory or will be freed? Monkey has garbage collection so objects that are NOT put on a list or in an array are freed when they go 'out of scope' (when you are not in their function) OverlapRect(ASprite1.getRect(),aSprite2.getRect()) aSprite2.getRect() creates an object which will be freed automatically if no other object has a reference to it (i.e. when you put it on a list) so... OverlapRect(ASprite1.getRect(),aSprite2.getRect()) is the absolutely correct way of doing things and is worry-free |