Return String?

BlitzMax Forums/BlitzMax Beginners Area/Return String?

xlsior(Posted 2006) [#1]
Is it possible to return a string from a function?

If I try something like this:

Function test(Inp$)
	Local output$="test"
	Print Inp$
	Return output$
End Function


I get is an 'Unable to convert from 'String' to 'Int' compile error.


Grey Alien(Posted 2006) [#2]
Yeah you need to specify the return type of the function:

Function test$(Inp$)

or

Function test:String(Inp$)



either works, I use the sorter one.

Do you code with Strict at the top? I advise this.


xlsior(Posted 2006) [#3]
Thanks, I just figured it out myself as well, and then I saw your response.

Do you code with Strict at the top? I advise this.


Not always... Sometimes I start without, and put it there later, fixing potential problems problems.


BladeRunner(Posted 2006) [#4]
I would recommend to use it always - I'm going even further and use superstict.
Keeps the Code clean from all kind of misspellings and the like. And you get used to it very fast.


Dreamora(Posted 2006) [#5]
Yes, always use strict. Not to fix problems, but because BlitzMax behaves elementally different when it comes to local - global - variable scopes if not strict is used. (it works then the Blitz3D way which means: a function is a scope and the whole program is a scope. But it does not know of loop, branch or any other local scopes!)


Grey Alien(Posted 2006) [#6]
using strict has saved me hours that I used to waste in BPlus when I accidentalyy misspelled a variable name and couldn't figure out why my code was going nuts until I realised the misspelling cos I was allow to use a misspelled var, it was just initialised at 0 and used!


CS_TBL(Posted 2006) [#7]
* uses superstrict always..

Tho, strict naming conventions does add some value in the coding process. The more uniform and regular your var/method-names are, the better.