returning a value from a function in superstrict

BlitzMax Forums/BlitzMax Programming/returning a value from a function in superstrict

Boulderdash(Posted 2007) [#1]
Im changing my program to be "super strict" compliant,
problem is, how do I return a value from a function, I dont understand how to do this in superstrict mode, it just gives me an error message? and the manual is non-existant for commands like this, just a BLANK entry in the help page makes it very differcult to figure out dont you agree everyone?


Perturbatio(Posted 2007) [#2]
You need to declare the return type:

Function getInt:Int()
return 1
End Function



Boulderdash(Posted 2007) [#3]
Thanks for your help, I get it now,

The type is placed before the brackets, now it works

eg:
Function Name:ReturnType(x:int)


H&K(Posted 2007) [#4]
just a BLANK entry in the help page makes it very differcult to figure out dont you agree everyone?
No

Functions
A function is a self contained block of code that can be called from multiple points in your program.

Functions are declared using the general syntax:
Function Identifier:ReturnType(Parameters)
Function Statements...
End Function
Functions are called using the syntax Identifier(Parameters).

If ReturnType is omitted, the function defaults to returning an Int.

Parameters is a comma separated list of parameters for the function. The syntax of each parameter is similar to a variable declaration: Identifier:Type. Function parameters may be used inside a function in the same way as local variables.

The Return statement is used to return a value from a function.

Here is an example of a simple function that adds 2 integers and returns their sum:

Function AddInts:Int( x:Int,y:Int )
Return x+y
End Function

This function can then be called by other code:
Print AddInts( 10,20 ) 'prints 30!


Function parameters can be assigned 'default values' using syntax similar to initializing a variable: Identifier:Type=ConstantExpression (note that default values for function parameters must be constant).

Default parameters can then be optionally omitted when the function is called:
Function IncInt:Int( n:Int,p:Int=1 )
Return n+p
End Function
Print IncInt( 1 ) 'Prints 2
Print IncInt( 1,3 ) 'Prints 4
Seems quite comprhensive to me. And definatly anwsers your question. The problem with haveing a reputation of a bad manual is that people dont even look at it.


SpaceAce(Posted 2007) [#5]
You can also use FunctionNameSHORTCUTSYMBOL, like this:

Function MyFunction%()
End Function


Function MyFunction#()
End Function

Function MyFunction$()
End Function

Function MyFunction!()
End Function


SpaceAce


Russell(Posted 2007) [#6]
H&K, I took his message as meaning that the explanation for "SuperStrict" in the manual was non-existant, in which case: He's correct (manual: "SuperStrict: Set SuperStrict mode". Ah, thanks for clearing that one up for me, BRL! ;)

I think we will all agree that the manual could be vastly improved, and that many things are un-explained or under-explained (even after many updates...)

Russell


H&K(Posted 2007) [#7]
@Russell, dont get me wrong I agree the Manual is rubbish. But its rubbish to the point, that even if it does have the answer to something, people dont lookit up.
In this case, Gav introdused Superstrict, and Got an error on a function. He looked superstrict up, that was no help. And even if he had looked "Function" as a keyword up, that would have been of no help.

However, this time the manual did have the anwser, in the "Learn the Language" bit. (As appossed to the Command index bit". (And dont forget the "Learn the Langaue" but is the manual, the other bit is just a refferance guide. So this time it was user error.

(But Yes, some of the stupid entries in the refferance bit are enough to drive you to dbPro ;)