Return float

Blitz3D Forums/Blitz3D Beginners Area/Return float

ILonion(Posted 2014) [#1]
Hello!
Why returned value is integer? I need original float. How can i do it?:

;#################
a# = fff()
DebugLog a#
WaitKey()
;#################
Function fff()
a# = 3.225
Return a#
End Function
;#################




GfK(Posted 2014) [#2]
You have to specify the return type in the function declaration:
Function fff#()
  a# = 3.225
  Return a#
End Function



ziggy(Posted 2014) [#3]
Maybe set the data in the function name ended with # That menas the result is a float


ILonion(Posted 2014) [#4]
Gfk, ziggy, thank you! It works.


Yasha(Posted 2014) [#5]
Unrelated extra advice:

1) You only need the # (or other signs) on variables when they're being declared, i.e. the very first appearance. You don't need to bother with it in future appearances, so you can save yourself some keystrokes.

2) Since you appear to be using IDEal, I would strongly recommend you turn on "Strict Mode". This adds the requirement that you formally declare all your variables with Local or Global, and paints any that you didn't in bright red. While it looks tedious to bother writing extra words that aren't necessary for the program to work, this is an absolute lifesaver when you're spending hours searching through your program for errors and it turns out it was a typo accidentally creating a new variable (e.g. misspelling "Vehicle" as "Vehcile" - finding these can be pretty frustrating without the red highlight).


H&K(Posted 2014) [#6]
If all the instances of the variable are within a screen hight, then possibly drop the #

However, its amazingly useful if the variable name has some indication of what type it is.
(I use BLIDE and BMax, so number of key presses have a lot less importance for me)
Plus In B3D can you be sure a variable isn't being redeclared?


GfK(Posted 2014) [#7]
If all the instances of the variable are within a screen hight, then possibly drop the #
Huh? Screen height is completely irrelevant.


H&K(Posted 2014) [#8]
Screen height is completely irrelevant. (Mmm maybe need better wording)

If all the instances of the variable are within "One Screen listing hight", then possibly drop the #.

That is if you can see ALL the uses of the variable on screen at the same time, then possibly drop the #.


ILonion(Posted 2014) [#9]
Thank you, Yasha, i'll do it...
(yes, it's IDEal).