Lerping function not working

BlitzPlus Forums/BlitzPlus Programming/Lerping function not working

indietom(Posted 2014) [#1]
I wrote this function in c# inialty and thought it would work in blitzPlus but it always returns the value of -27 * 10^5 or something.

Here's the function itself
Function lerp(x#, y#, t#)
	Local value#
	Return value# = t# * y# + (1-t#) * x#
End Function


Here's where I use the function:
 elevator\y = lerp(elevator\y, 0, 0.7) 


Thanks for any help


Matty(Posted 2014) [#2]
The function needs to have its return type declared.

Try Function lerp# instead of just function lerp


indietom(Posted 2014) [#3]
Thanks for the help!


Yasha(Posted 2014) [#4]
It should be one of:

Function lerp#(x#, y#, t#)
	Return t# * y# + (1-t#) * x#
End Function

;or

Function lerp#(x#, y#, t#)
	Local value# = e = t * y + (1-t) * x    ;(type sigils are not needed after declaration)
	Return value
End Function


When used as a subexpression, `value = ...` is an equality test producing a boolean (integer) value. `=` only works as assignment when standing as a statement on its own, or to initialize a variable declaration (like in the second snippet). So the original version is trying to return 1 or 0 in all cases, not any kind of interpolated value.