
-----------------------------------
Raknarg
Sun May 06, 2012 3:38 pm

Importing not working
-----------------------------------

module Initialize
    import "Ship.tu"
    var Init : array 1 .. 21 of proc x
end Initialize


I have this module here, and as said above, it wont let me import for some reason. It gives me an error at "Ship.tu" saying "identifier expected". Any ideas?

-----------------------------------
Dreadnought
Sun May 06, 2012 3:56 pm

Re: Importing not working
-----------------------------------
The syntax for importing units goes like this:

Assuming ship is the name of the class of module in the unit

If the are in the same folder (and the module or class name is the name of the file)

import ship   % Note the lack of quotation marks and file extension


If they are in a different folder (or if the module or class in the unit is not also the name of the file)


import ship in "etc/ship.tu"  % Where "etc/ship.tu" is the relative path


-----------------------------------
Raknarg
Sun May 06, 2012 5:20 pm

RE:Importing not working
-----------------------------------
You can do the file or the name of the module, actually, assuming they are in the same folder; I've done it before. In fact, I tried it with the other one and got the same error

-----------------------------------
Aange10
Sun May 06, 2012 6:07 pm

RE:Importing not working
-----------------------------------
I can support what Rak said, as you can just type import "filename.tu" because that's how i do it in all my programs.

I think your problem might be that you can only import on the very first line of the program? You can include anywhere, but i'm pretty sure you can only import on the very beginning line.

-----------------------------------
Raknarg
Sun May 06, 2012 7:16 pm

RE:Importing not working
-----------------------------------
No, It has to be at the beginning of any object, module or program. They're like seperate programs I suppose, so they can have different instances of importing.

I can attest to that with my Scrollbox class, where I import buttons.

-----------------------------------
smool
Sun May 06, 2012 9:19 pm

RE:Importing not working
-----------------------------------
kind of off topic, but what's the difference between import and include?

-----------------------------------
Raknarg
Mon May 07, 2012 8:37 am

RE:Importing not working
-----------------------------------
I beleive import works for units, but with include you can include other programs, so you can store data structures and procedures and such.

-----------------------------------
Amarylis
Mon May 07, 2012 8:44 am

RE:Importing not working
-----------------------------------
Import, you get access to all the subprograms of the module/class/monitor, whereas include just literally copies all the code that's in the file and adds it to the current code.

-----------------------------------
Dreadnought
Mon May 07, 2012 11:50 am

Re: Importing not working
-----------------------------------

You can do the file or the name of the module, actually, assuming they are in the same folder; I've done it before. In fact, I tried it with the other one and got the same error

Oh, sorry, I had always done things that way. But here's something else to try.

If the code is in the main program then this applies:
Turing initializes modules and monitors in order of importation. Initialization begins with the main program, which first initializes its imports in the order given in its import list, and then initializes itself.

Since this is the main program, the main program must import the modules/classes/etc first, in order for them to be initialized, then they can be imported into any module or class within the main program. (Aange mentioned this)

So you need to structure thing like so.

import 

module MyModule
   import 
   ...

end MyModule
Everything in the import list for the module must also be in the import list of the main program.
Of course, if this is not in your main program then it may not apply.

-----------------------------------
Raknarg
Mon May 07, 2012 7:39 pm

RE:Importing not working
-----------------------------------
Oh, I had never thought of that. Thanks, I'll give that a try.

-----------------------------------
copthesaint
Mon May 07, 2012 9:32 pm

Re: Importing not working
-----------------------------------

module Initialize
    import "Ship.tu"
    var Init : array 1 .. 21 of proc x
end Initialize


I have this module here, and as said above, it wont let me import for some reason. It gives me an error at "Ship.tu" saying "identifier expected". Any ideas?

instead of:

import "Ship.tu" 

use:

import Ship in "Ship.tu"

-----------------------------------
evildaddy911
Mon May 07, 2012 10:11 pm

RE:Importing not working
-----------------------------------
Copthesaint, if you had read the entire thread, you would have noticed that you can just use the file name, and that the problem was in where the import was located, not how the module/class was imported

-----------------------------------
Raknarg
Tue May 08, 2012 11:01 am

RE:Importing not working
-----------------------------------
@Dreadnought that seemed to work, thanks. We'll see how this works once we turn the the class and module into units.
@copthesaint As I said before: You can do the file or the name of the module, actually, assuming they are in the same folder; I've done it before. In fact, I tried it with the other one and got the same error
