Include problem

Blitz3D Forums/Blitz3D Beginners Area/Include problem

Farflame(Posted 2007) [#1]
I've never used the include command much, but my game is becoming very bulky and the interpreter keeps crashing when I move blocks of text around, so I've decided to split the working parts into a couple of seperate include files. However, I have a problem....

I've split the functions into one include file, and data into another file. I include them at the start of my main file, but when I run it, the functions file stops and says that it can't find the data (from the data file). In other words, program 1 loads in programs 2 & 3, but program 2 stops because it can't find some of the data from program 3.

I get the error, 'Function Shortratings$ not found', when Shortratings$ is actually an array created at the start of the main file, using data from the data file.

For now I'll just stick them all together again, but I'd like to solve this as the files are becoming too large.


Mortiis(Posted 2007) [#2]
Have you declared variables as Global? Even if they are in function put Global VariableName at the top of the source file.

Like;

Global VariableName

Function Test()
    VariableName = BlaBla
End Function



Farflame(Posted 2007) [#3]
I don't think that's the problem, because this is an array, which I believe is global anyway? It's declared at the top of the main file, it then reads it's information using restore / read (that information is now in the 2nd include file), but the other include file doesn't seem to know that the array even exists.

I've stuck the file back together and it works fine as a single file :(


nrasool(Posted 2007) [#4]
Hi Farflame,

I don't think an Array is global, you need to declare it, eg

Global variable_name[2]



big10p(Posted 2007) [#5]
Are you sure you put the include command AFTER the Dim command for the array?


GfK(Posted 2007) [#6]
I don't think an Array is global, you need to declare it
Dim Array(n) makes a global array - they're global by default in Blitz3D. As for Array[n] (i.e. Blitz arrays) - can't remember if they're global by default or not. I don't *think* they are, so it depends how you're doing it.

Make sure you're trying to compile the right file; i.e. the main one that calls the Includes. If you try to compile any of the others then yep, you'll get errors.


Bankie(Posted 2007) [#7]
Ok, did a couple of tests and hope I can help. You have to make sure that when you put your include statements at the beginning of your main document, that you put them in the right order. The include file which contains the Dim statements must go first. For normal global variables it doesn't appear to matter, but for arrays, the Dim statement has to be encountered first so that the compiler knows that it exists. In short, the first include statement should be the one that points to your variable declarations.


Farflame(Posted 2007) [#8]
Ok, thanks for the help guys, will try this out later and let you know.