Can I import .monkey files
Monkey Forums/Monkey Programming/Can I import .monkey files
| ||
Is it possible to import another .monkey file in my own .monkey file? |
| ||
have you tried it? (I'm guessing include is what you want rather than import) |
| ||
yes I tried but I get an compile error: This is my other .monkey file Extern Class tester Method dt() DrawText "Tester", 100, 100 End End Maybe I'm doing something wrong. In my main file I Import tester (name of other monkey file) |
| ||
Hmm... it's causing an error for me too. |
| ||
Extern is for linking with other languages not for sharing code between monkey files. |
| ||
This seem to work Class tester Method dt() DrawText "Tester", 100, 100 End End It does not give an error, now I will check if it actually works |
| ||
How do I call the methods in my main file? |
| ||
Hi Tri... The easiest way to deal with this is to import all of your import files within your main file: main.monkey: Import myplayer Import myenemy Import mybullet ... etc... ... then import your main file into all the others: myplayer.monkey: Import main myenemy.monkey: Import main mybullet.monkey: Import main This way, all of the import files can 'see' everything in all of the other imports (by looking at what's in main), so you'll be able to access myplayer from mybullet, mybullet from myenemy, etc. See the rockout sample, which does exactly this -- it's very easy to deal with things this way! Just add any new imports to the main file, and make sure all new imports have "Import main.monkey" (or whatever) at the top. |
| ||
I tried that but it still will not regonize the dt method in my main |
| ||
Something like this?Class tester Method dt() DrawText "Tester method", 100, 100 End Function dt() DrawText "Tester func", 100, 100 End End In your main file (possibly in OnRender() ): Local t := New tester t.dt() tester.dt() Untested. |
| ||
Nope! Says NClass tester not found |