Does anybody know how to identify an array as global? The instructions say that arrays are automatically set as global, but they are never recognised when I try to access them from my functions.
Global arrays
BlitzPlus Forums/BlitzPlus Programming/Global arrays Arrays are Global by default Game Boy (not strictly true but keep to the basics first).
You may be trying to access them the wrong way. If you post a little bit of code showing your array declaration and the function that is trying to access the array, I may be able to help.
You may be trying to access them the wrong way. If you post a little bit of code showing your array declaration and the function that is trying to access the array, I may be able to help.
Try this...
[Code]
Graphics 640,480,32,2
SetBuffer BackBuffer()
Dim spellings$(10)
example
Text 10,10,spellings$(0)
Flip
Repeat
Until KeyHit(1)
End
Function example()
spellings$(0) = "test"
End Function
[/Code]
[Code]
Graphics 640,480,32,2
SetBuffer BackBuffer()
Dim spellings$(10)
example
Text 10,10,spellings$(0)
Flip
Repeat
Until KeyHit(1)
End
Function example()
spellings$(0) = "test"
End Function
[/Code]
Solved the problem :-). I've included all of the functions at the top of the code before the arrays were defined, which made the compiler think that the arrays were never defined.
Many thanks for all your help Prof and Becky - very much appreciated.
Many thanks for all your help Prof and Becky - very much appreciated.
Prof's code should work. you must be doing something funny Gameboy. When you say the array is not recognised, do you mean by the compiler, or that it appears that way because when you access an array slot (to print for example) later, you are getting null values? A bugbear I have with the Blitz IDE is that it doesn't warn you if you type a variable name incorrectly and so many times I have wondered why my code doesn't work only to find a misplaced/missing letter. Also if you pass a string into a funciton and forget to stick $ on the end of it, it's treated as an integer and your output is always 0 (this isn't a compiler issue really, just me being dumb)
Game Boy...
It always helps if you post a bit of code first :)
It always helps if you post a bit of code first :)
the code looked like this
It was becuase the functions were at the top, the complier hadn't read the definition of the array, hence it thought that it didn't exist.
Now that I have included all extra files at the bottom of the code, everything is fine.
include functions here... dim array(10) ...etc... function example() array(0) = 10 end function
It was becuase the functions were at the top, the complier hadn't read the definition of the array, hence it thought that it didn't exist.
Now that I have included all extra files at the bottom of the code, everything is fine.