Computer Science Canada Importing Modules |
Author: | Aange10 [ Sun Sep 18, 2011 11:58 pm ] |
Post subject: | Importing Modules |
What is it you are trying to achieve? I've made a module with a procedure in it to make a main menu. I want to import that module into my game, and run the procedure. What is the problem you are having? I'm getting a syntax error at Import. Describe what you have tried to solve this problem I've read http://compsci.ca/v3/viewtopic.php?t=4303 fully, and followed everything there and there is still a syntax error. I've searched the forums for others with the same problems (am I alone?? hah) I've look at the turing help reference (F10), but their explaination of: Quote: import [ howImport ] importItem {, [howImport] importItem } is not useful at all. Their description is also totally confusing. Post any relevant code (You may choose to attach the file instead of posting the code if it is too long) Here is the folder I'm working with (Note I have the module saved two different ways, it's just my attempts at getting it right.) Please specify what version of Turing you are using 4.0 (I think, it's the latest version with the generate standalone working) ALL MY TESTING IS IN GAME-TESTING.t, you will NOT find anything under game.t (unless you want to play it.. heh) |
Author: | Nick [ Mon Sep 19, 2011 12:03 am ] |
Post subject: | RE:Importing Modules |
you simply type import module'sFileNameWithoutExtension as the first line of your code |
Author: | Aange10 [ Mon Sep 19, 2011 12:05 am ] |
Post subject: | RE:Importing Modules |
Ahh so the problem was it HAS to be the FIRST line of code... I didn't know that D:. Thankyou very much! |
Author: | Aange10 [ Mon Sep 19, 2011 12:11 am ] |
Post subject: | Re: Importing Modules |
Though, is there a way I could make the variables that change in the procedure change for the main program too? (Instead of JUST locally within the proc?) NOTE: Updated file: |
Author: | Raknarg [ Mon Sep 19, 2011 4:35 pm ] |
Post subject: | RE:Importing Modules |
I believed thats achieved with either exporting or pointers or something |
Author: | Aange10 [ Mon Sep 19, 2011 4:39 pm ] |
Post subject: | RE:Importing Modules |
Hmm, could make a function that does the procedure, and use the result (i think is the name) command to get the varriables? |
Author: | Aange10 [ Mon Sep 19, 2011 6:01 pm ] |
Post subject: | Re: Importing Modules |
I read Pointers and I've read Functions & Procedures to try and solve this problem, and so I think I've found something close to my answer (Yay!). The pointers thread didn't help me too much. Really I think it's just because it didn't really give a good example of its use. However, the Functions and Procedures thread did help. So, I'm posting a reply here to ask a few questions. 1.) Is it possible to make a function that will run the procedure, and give me all my variables as real numbers (and then i can convert my needed variable to int)? 2.) Cervantes said Quote: Nice functions are ones that compute a value based soley on the parameters they take. is there a way that my procedure will compute the values (If you run through the main menu, or look at the coding, you see how depending on which character you pick the variables change.) and my function will give me the result?? Thanks to anybody who takes the time to read this! (I've spent about two hours toying with these arcane methods, and I appreciate all the help I can get.) |
Author: | Insectoid [ Mon Sep 19, 2011 7:36 pm ] |
Post subject: | RE:Importing Modules |
You could use a function, and abandon the procedure altogether. A function is just a procedure that returns a value. |
Author: | Aange10 [ Mon Sep 19, 2011 8:37 pm ] |
Post subject: | RE:Importing Modules |
Sounds good to me! Only one problem with that. How do i make a function give more than one result? |
Author: | Tony [ Mon Sep 19, 2011 9:30 pm ] |
Post subject: | RE:Importing Modules |
return a multi-value type, such as a record |
Author: | Aange10 [ Mon Sep 19, 2011 10:59 pm ] | ||
Post subject: | Re: Importing Modules | ||
Alright, so I've spent the last 2 hours trying to make my functions output a record. Here are some of the things I've tried doing to make it work (in probably every combination...) Firstly I made something that looked like this:
From there I started refining the coding. And these are the things I've spent two hours changing: 1. I've made the record exclusively local to the function. I've also tried making the record both global and local. 2. I've tried different parameters for function MainMenuF: .. I've tried type,record, and PlayerData 3. I've tried different parameters for result PlayerData: .. I've tried type, var, record, PlayerData 4. I've ALSO tried to use the "var a : PlayerData" technique, and have substitute it for PlayerData in (i think) every combination i've tried. 5. I've fully read the Pointer, Functions and Procedures, Records (quite pointlessly...) The Dir Module, and functional programming in Turing [skimmed], tutorials. 6. I've searched the forums for the key words 'function record' and browsed the posts. -- So, is there a way I could maybe see a function that does what I'm trying to achieve? I want my module (posted a few up) to give me the variables it changes in the procedure. If I need to change the procedure to a function and it be that simple, then awesome. But I'd absolutely love whomever could show me a function that takes in global variables and outputs a record (or however to make it work) ... I just want to make it clear my intentions are not to be bothersome or a waste you guys' time; I'm wasting more of my time than I'd like as is. My goal is to learn this and complete the task I'm trying to do, not decimate whatever free time I have ![]() EDIT: Haha see what I get for trying to clean up my coding? 2 days of researching and fiddling! But at least once I learn it, I know it!(: |
Author: | Tony [ Mon Sep 19, 2011 11:37 pm ] | ||
Post subject: | RE:Importing Modules | ||
|
Author: | Zren [ Tue Sep 20, 2011 1:53 am ] | ||
Post subject: | RE:Importing Modules | ||
You can't modify variables passed as parameters in Turing Tony. Not too big a deal. Rather inefficient (but alas, it is Turing). You just have to copy it into a new variable first. It's still rather annoying.
|
Author: | DemonWasp [ Tue Sep 20, 2011 7:32 am ] | ||
Post subject: | Re: RE:Importing Modules | ||
Zren @ Tue Sep 20, 2011 1:53 am wrote: You can't modify variables passed as parameters in Turing
Lies. The following:
will output 5. Also, Tony's code doesn't modify local_data itself, it modifies the contents of local_data (different, and most languages allow the latter). |
Author: | Tony [ Tue Sep 20, 2011 12:38 pm ] |
Post subject: | Re: RE:Importing Modules |
Ops. Hard to keep up with all the subtle differences between languages. Zren has the right idea (if there are multiple functions that perform operations, the copy of a record can be factored out into its own function). DemonWasp's pass-by-reference also works, but I find such code to be less intuitive. You'd still need to do the whole copy-record code if you want the original to not be modified (e.g. calculate new position to check if it's a valid move). I suppose that depends on the use cases. DemonWasp @ Tue Sep 20, 2011 7:32 am wrote: Tony's code doesn't modify local_data itself, it modifies the contents of local_data (different, and most languages allow the latter).
That would have been the case for objects, but I think records are flat data-structures. |
Author: | Aange10 [ Tue Sep 20, 2011 6:41 pm ] | ||
Post subject: | RE:Importing Modules | ||
So why doesn't
work? And how do i fix it |
Author: | Tony [ Tue Sep 20, 2011 7:16 pm ] |
Post subject: | RE:Importing Modules |
follow what the compiler tells you when you try to run this code. Also Zren @ Tue Sep 20, 2011 1:53 am wrote: You can't modify variables passed as parameters in Turing... |
Author: | Aange10 [ Thu Sep 22, 2011 8:33 pm ] |
Post subject: | Re: Importing Modules |
Thanks a ton guys. I got frustrated and took a break for a few days, and I've come back with a clear mind and figured it out(: .. Much thanks!! (Really don't know where I'd be without you!) Here is the code |
Author: | Aange10 [ Mon Sep 26, 2011 8:06 pm ] |
Post subject: | RE:Importing Modules |
Hmmm, out of everything I've been doing I didn't figure I'd be asking this question.. but.. How can i make a string take in more than one word? If i type "Hello World" it will only show "Hello". I've actually read all the tutorials, used the turing help and tried to search the forums (3000 posts t-t) for this problem. Anybody have an answer as to how to do this? |
Author: | DemonWasp [ Mon Sep 26, 2011 10:27 pm ] |
Post subject: | RE:Importing Modules |
This question gets asked about once a week, so I'm surprised it doesn't show up in search results: get my_variable : * that :* tells "get" to "get everything up to the end of line". Otherwise, get assumes you want to get just up to the first space. You can read about this in the Turing help on the get command. |
Author: | Aange10 [ Mon Sep 26, 2011 10:59 pm ] |
Post subject: | RE:Importing Modules |
Thankyou demon! And yes, I suppose I didn't check get, only string... =/ Sorry about that; I didnt think that get would have a specific syntax/parameter for strings w/ spaces |
Author: | Aange10 [ Mon Sep 26, 2011 11:31 pm ] | ||
Post subject: | Re: Importing Modules | ||
I've run into another hindrance... Although this one may be a bit over my head; I'm working on a program that I can put information into and it will format it for me. (Ughh, all the work, so much easier to program it(: ) The file is at the bottom here [VERY self explanatory. The file is written simply, and I have no need to make it more compact; it will never be used for another purpose/ or be expanded on.] I've come to a problem. The program works (and does quite well). However, to make my life easier, I'd like to have it paste the information it gives me straight into a .docx file. [Why copy and paste when I can make the computer do it for me?] My problem, though, is that when i try to do this it corrupts my .docx file. Is there anything I can do about this? Does it happen in most languages, or is turing just lame? Here is the example coding I was using to test.
I also tried the above using the write command instead of the put commands, I had the same result. |
Author: | Nick [ Tue Sep 27, 2011 7:38 am ] |
Post subject: | RE:Importing Modules |
The issue is that docx files are not plain text, they are binary files. Unless you know the encoding for the format (which I'm sure you could Google but it'd be a hell of a lot easier to copy/paste) you can't really do this with turing.... come to think of it it still may not be possible as there are some characters that turing cannot handle... tl;dr just copy/paste |
Author: | DemonWasp [ Tue Sep 27, 2011 7:54 am ] |
Post subject: | RE:Importing Modules |
In particular, all of the Office Open XML (not to be confused with OpenOffice XML) formats are zipped file formats. That means that, to even read the underlying XML, you would need to implement unzipping in Turing. Once you have that, you would have to read and understand the existing document. The specification for how to do this is about 6,000 pages long, as I recall. Then you would have to modify the document, push it all out as XML and then zip it again. Just use Word (or OpenOffice, or LibreOffice). |
Author: | Aange10 [ Tue Sep 27, 2011 4:31 pm ] |
Post subject: | RE:Importing Modules |
Alright thanks a ton you guys! |
Author: | Aange10 [ Sun Oct 02, 2011 11:43 am ] |
Post subject: | RE:Importing Modules |
I've been playing around a lot with having turing open/close things [internet explorers, executables, facebook.. etc.] and I've decided to try and write a tutorial on Turing about Turing because I want to help some of my friends learn the language. However I'm running into the problem with them needing to run it with administrative privileges. Now, that isn't a problem [they trust me] but what is a problem is it's really annoying to right click and run as admin. Is there a way I can make it ask them for admin privledges when they run it? (Like the little popup window with the allow/disallow thing) Do I do this in the coding of the program, or do i manually edit the properties of the .exe to 'run as admin'? (will it work when i send it to their computers?) |
Author: | Nick [ Mon Oct 03, 2011 10:36 am ] |
Post subject: | RE:Importing Modules |
Right click turing.exe -> properties -> compatibility mode -> run this as an administrator |