Programming C, C++, Java, PHP, Ruby, Turing, VB
Computer Science Canada 
Programming C, C++, Java, PHP, Ruby, Turing, VB  

Username:   Password: 
 RegisterRegister   
 Importing not working
Index -> Programming, Turing -> Turing Help
View previous topic Printable versionDownload TopicSubscribe to this topicPrivate MessagesRefresh page View next topic
Author Message
Raknarg




PostPosted: Sun May 06, 2012 3:38 pm   Post subject: Importing not working

Turing:

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?
Sponsor
Sponsor
Sponsor
sponsor
Dreadnought




PostPosted: Sun May 06, 2012 3:56 pm   Post subject: 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)
Turing:

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)

Turing:

import ship in "etc/ship.tu"  % Where "etc/ship.tu" is the relative path
Raknarg




PostPosted: Sun May 06, 2012 5:20 pm   Post subject: 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




PostPosted: Sun May 06, 2012 6:07 pm   Post subject: 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




PostPosted: Sun May 06, 2012 7:16 pm   Post subject: 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




PostPosted: Sun May 06, 2012 9:19 pm   Post subject: RE:Importing not working

kind of off topic, but what's the difference between import and include?
Raknarg




PostPosted: Mon May 07, 2012 8:37 am   Post subject: 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




PostPosted: Mon May 07, 2012 8:44 am   Post subject: 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.
Sponsor
Sponsor
Sponsor
sponsor
Dreadnought




PostPosted: Mon May 07, 2012 11:50 am   Post subject: Re: Importing not working

Raknarg wrote:

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:
http://compsci.ca/holtsoft/doc/import.html wrote:
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.
Turing:

import <import list for main program>

module MyModule
   import <import list of module>
   ...

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




PostPosted: Mon May 07, 2012 7:39 pm   Post subject: RE:Importing not working

Oh, I had never thought of that. Thanks, I'll give that a try.
copthesaint




PostPosted: Mon May 07, 2012 9:32 pm   Post subject: Re: Importing not working

Raknarg @ Sun May 06, 2012 wrote:
Turing:

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:

Turing:
import "Ship.tu"


use:

Turing:
import Ship in "Ship.tu"
evildaddy911




PostPosted: Mon May 07, 2012 10:11 pm   Post subject: 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




PostPosted: Tue May 08, 2012 11:01 am   Post subject: 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
Display posts from previous:   
   Index -> Programming, Turing -> Turing Help
View previous topic Tell A FriendPrintable versionDownload TopicSubscribe to this topicPrivate MessagesRefresh page View next topic

Page 1 of 1  [ 13 Posts ]
Jump to:   


Style:  
Search: