Variable type

BlitzMax Forums/BlitzMax Beginners Area/Variable type

jankupila(Posted 2010) [#1]
This is maybe easy and silly question but what's wrong with the code:
This give's an error "Missing type specifier"



SuperStrict
Graphics 800,600

Global Nimi:String
Global Id:Int
Global Ika:Int
Global totaldata:String
Global testdata:String

TestData = Keraa_tieto("Blast", 8, 30)
DrawText TestData,10,10

Flip
WaitKey

Function Keraa_tieto:String ( Nimi, Id, Ika )'<---There is the error 
TotalData = "Name:"+Nimi+", ID:"+Id+", ikä:"+Ika
Return TotalData
End Function


Last edited 2010


jankupila(Posted 2010) [#2]
I want to make 'superstrict' code.


Zeke(Posted 2010) [#3]
you need to tell function arguments types:
like nimi:String,ID:int,Ika:int


jhans0n(Posted 2010) [#4]
Zeke's right, but I have another question. Why are you passing Nimi, Id, and Ika into the function if they are Globals? They're already accessible within the scope of the function.

Also, you want to watch your capitalization in SuperStrict mode. TestData vs testdata, for instance.


jankupila(Posted 2010) [#5]
They were Globals because I wasn't sure are the 'Local' variables visible in the function. It was just a try when I was seeking the error.
I changed the line as this:

Function Keraa_tieto:String ( Nimi:String, Id:Int, Ika:Int )

and it works!

Thanks a lot!

Last edited 2010

Last edited 2010


Czar Flavius(Posted 2010) [#6]
Whatever you pass as a paremeter, is always visible inside a function (but perhaps under their new names as given by the parameter list)

Superstrict isn't case-sensitive, but it's a good idea to be consistant to avoid confusion.

SuperStrict
Graphics 800,600

Local TestData:String = Keraa_tieto("Blast", 8, 30)
DrawText TestData,10,10

Flip
WaitKey

Function Keraa_tieto:String ( Nimi:String, Id:Int, Ika:Int )
	Local TotalData:String = "Name:"+Nimi+", ID:"+Id+", ikä:"+Ika
	Return TotalData
End Function


Last edited 2010


Gabriel(Posted 2010) [#7]
Whatever you pass as a paremeter, is always visible inside a function (but perhaps under their new names as given by the parameter list)

I think Jankupila means that they were always locals but he changed them to Globals just to see if they made the error go away.


TomToad(Posted 2010) [#8]
Note that when you pass a variable to a function like that, the function will work on a local copy of the variable instead of the global as this program illustrates
SuperStrict

Global MyNumber:Int

MyNumber = 10
Print "MyNumber before call = "+MyNumber

Add10(MyNumber)
Print "MyNumber After call = "+MyNumber

Function Add10:Int(MyNumber:Int)
    MyNumber :+ 10
    Print "MyNumber within function = "+MyNumber
End Function

If you need the function to work on the Global, then don't pass it to the function
SuperStrict

Global MyNumber:Int

MyNumber = 10
Print "MyNumber before call = "+MyNumber

Add10()
Print "MyNumber After call = "+MyNumber

Function Add10:Int()
    MyNumber :+ 10
    Print "MyNumber within function = "+MyNumber
End Function



jankupila(Posted 2010) [#9]
Ok. I see what you mean. Thanks!