Variable type
BlitzMax Forums/BlitzMax Beginners Area/Variable type
| ||
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 |
| ||
I want to make 'superstrict' code. |
| ||
you need to tell function arguments types: like nimi:String,ID:int,Ika:int |
| ||
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. |
| ||
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 |
| ||
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 |
| ||
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. |
| ||
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 illustratesSuperStrict 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 |
| ||
Ok. I see what you mean. Thanks! |