More Monkey to Blitzmax Confusion

BlitzMax Forums/BlitzMax Programming/More Monkey to Blitzmax Confusion

RustyKristi(Posted 2016) [#1]
This is in Strict mode, I'm having problems with Monkey conversion. For now I just replaced Class with Types but this is the exactly code that works with MX.

Type Obj
  Field x
  Field y
  Field _foo:Float = 1 

  Field _epivot:TEntity

  Method New(foo:Float = 1.0, epivot:TEntity)
    _foo     = foo
    _epivot = epivot
  End Method

End Type


Error: Identifier 'foo' not found (works without Strict)
Error: Unable to convert from 'Int' to 'TEntity' (epivot variable)


degac(Posted 2016) [#2]

In BlitzMax you can't override New method (or passing parameters to it)


RustyKristi(Posted 2016) [#3]
Thanks degac! It kinda works with those adjustments

Some questions though

1) Can I use Method instead of Function? Just to make the conversion as close as possible.

2) Inside the create function/method, there's an existing statement that uses self like

CustomFunction( self._piv )

Apparently it works. Do I leave it or use the example Local n that I first declared.

So the updated code is now

Type Obj
  Field x
  Field y
  Field _foo:Float = 1 
  Field _pivot:TEntity

  Field _epivot:TEntity

  Method New(foo:Float = 1.0, epivot:TEntity)
    _foo     = foo
    _epivot = epivot

    HideEntity( Self._pivot )
  End Method

End Type



Brucey(Posted 2016) [#4]
The legacy BlitzMax compiler doesn't support overloaded constructors (i.e. New(something)).

The conventional way to get around this limitation/feature is to use a "Create" method or function.

A create method generally returns an instance of itself, and is usually used in conjunction with New :
Local myObj:TObj = New TObj.Create(10, 100)

...

Type TObj
...
    Method Create:TObj(x:int, y:int)
      ...
      Return Self
    End Method
...
End Type


Using a create function follows similar lines, except that you need to create an instance of the object yourself :
Local obj:TObj = TObj.Create(10, 100)


Type TObj
...
    Function Create:TObj(x:int, y:int)
      Local obj:TObj = New TObj
      obj.x = x
      ... etc

      Return obj
    End Function


The method convention better supports polymorphism.


Also, the latest BlitzMax NG allows you to use overloaded New(), just like in Monkey. But YMMV...


RustyKristi(Posted 2016) [#5]
Thanks guys, I think I'm getting it now as some of my functions are not throwing errors anymore. I will work on other conversion stuff and see if this will push through.