Import command not working perfectly in Beta?

BlitzMax Forums/BlitzMax Programming/Import command not working perfectly in Beta?

PowerPC603(Posted 2004) [#1]
I've ported my entire datafile-load-procedure from Blitz3D to BMax.

I've split up my project into separate .bmx files (it's more managable than having everything in one big source-file).

Zip-file with separate files: http://users.pandora.be/vge/SG/SG_SeparateFiles.zip
Zip-file with all code in 1 big sourcefile: http://users.pandora.be/vge/SG/SG_EntireFile.zip

When I run the project (file "SpaceGame.bmx", which include all other sourcecode-files), it produces an error on this line:

For i = 1 To Universe.NumSec%


Error: Identifier "NumSec% not found

When I copy the entire contents of all other sourcefiles into the file SpaceGame.bmx, it runs perfectly.

Is there something missing from my part, or is it just that this project is run by the Beta-version?

I've made sure that all files (and pathnames) have no spaces in them.

Also, if I remove the file "Includes\IncludeAllSources.bmx" and copy the contents of this file into the main project file "SpaceGame.bmx", it seems it cannot find the function "GetParameterName", even if it's included before all classes.

Also, then I have to include the file Class_Sector.bmx" before the file "Class_Universe.txt", because it couldn't find the identier "TSector" when compiling the type TUniverse.
This is not required when all files are merged together.

And it seems that the "Include"-command is gone, is this replaced by the "Import"-command?


PowerPC603(Posted 2004) [#2]
Never mind, I've found it already.

The Include still works, but isn't recognised as a keyword.
I was searching through the samples and found that the TeraBit's GLHead sourcecode file still used the command "Include", so I gave it a try, and now it works.

Thanks anyway.


marksibly(Posted 2004) [#3]
Hi,

Okay, a few things:

Your main file imports a '.bb', not a '.bmx'. Max is silently ignoring this, which is a bit naughty and will be fixed.

Also, your ImportAllSources imports stuff from 'Include/' - but Import works relative to the file's directory so it ends up looking for 'Include/Include/blah'!

Finally, Imports can not be 'cyclic'. The idea is for files to import just what they need (ie: Universe should Import Sector if it needs it) so your 'ImportAllSources' approach is likely to eventually fail.

The easiest way around this is simply to use Include instead of Import in IncludeAllSources. However, you will not get the benefit of faster compile times this way.


Jim Teeuwen(Posted 2004) [#4]
it takes a bit of getting used to. I reported a potential bug about this last week, but it turned out I was at fault. I'd suggest playing with some test includes a bit to get anidea of how they work. It'll save you quite a headache later on.


PowerPC603(Posted 2004) [#5]

Also, your ImportAllSources imports stuff from 'Include/' - but Import works relative to the file's directory so it ends up looking for 'Include/Include/blah'!



I've noticed this when I used the Include command, as BMax gave me an error that he couldn't find those files.

So, if more than one sourcefile needs the command "GetParameterName", than all those sourcefiles (which require the command "GetparameterName") must "Import" this file "Lib_GetParameterName_Value.bmx", when I use the command Import?

And what exactly do you mean by cyclic?
I saw this in the help-files sometimes, but I don't quite understand what it means (my main language is Dutch).

Does it mean that if you have a mainfile called "Project.bmx" and you Import the file "File1.bmx", which imports "File2.bmx", that this "File2.bmx" is not allowed to Import "File1.bmx" again?


Dreamora(Posted 2004) [#6]
cyclic means the following

source of a.bmx:

import "b.bmx"

source of b.bmx:

import "a.bmx"

which creates an "endless import loop" if you want to call it that way. as it jumps forth and back between this 2 files endlessly.

Your sample is no problem as there are several core modules which already do it this way.


FlameDuck(Posted 2004) [#7]
And what exactly do you mean by cyclic?
It means (litterally) going around in circles. The simplest example of which Dreamora explained above.