Will this work? (Can't test it atm)

BlitzMax Forums/BlitzMax Beginners Area/Will this work? (Can't test it atm)

Chroma(Posted 2010) [#1]
The part below I'm wondering about is the 'b:TBlah=Self'. Since it's a Method, can you use Self as a default argument?

Type TBlah
     Field x,y

     Method Do(a:TBlah,b:TBlah=Self)
          Self.x = a.x + b.x
          Self.y = a.x + b.x
     End Method
End Type



plash(Posted 2010) [#2]
No.


Chroma(Posted 2010) [#3]
Thanks for testing.


TomToad(Posted 2010) [#4]
You can fudge it a bit
Type TBlah
     Field x,y

     Method Do(a:TBlah,b:TBlah=Null)
          If Not b then b = Self
          Self.x = a.x + b.x
          Self.y = a.x + b.x
     End Method
End Type



Chroma(Posted 2010) [#5]
Hah! That's exactly what I did. I think the hit is negligible...the purists/speedfreaks will cry foul of course.

I was trying to do that with subtraction but it's a different ballgame...


Chroma(Posted 2010) [#6]
Meh nm...I guess the spirits are helping me...

Method Do2(a:TVec3,b:TVec3=Null)
	If Not b Then b = Self Else b = a
	Self.x = b.x - a.x
	Self.y = b.y - a.y
	Self.z = b.z - a.z
End Method



Chroma(Posted 2010) [#7]
Hmm...seems I need an operator that changes a variable to the opposite of what it is. I thought it was the bitwise but that doesn't work on floats...

Nm: Forgot about putting a "-" in front.


Chroma(Posted 2010) [#8]
Bleh...this works...

Method Sub(a:TVec3,b:TVec3=Null)
	If Not b
		b = a
		a = Self
	EndIf
	Self.x = a.x - b.x
	Self.y = a.y - b.y
	Self.z = a.z - b.z
End Method



ImaginaryHuman(Posted 2010) [#9]
Why would you want to pass `Self` when Self is only useable within the method anyway?


Czar Flavius(Posted 2010) [#10]
Don't take this the wrong way, but I think you're trying to be too clever for your own good. It looks like you are trying to implement some kind of clever trick or shortcut. Just stick to straightforward vector methods and keep things simple :P