Importing same file to multiple separate projectsMonkey Forums/Monkey Beginners/Importing same file to multiple separate projects
| I need to import level.monkey into both my editor and main game.|
In level.monkey I'm forced to have "import game" but then when the editor tries to import the same level.monkey file, there are of course problems, since level.monkey should really be calling "import editor" now.
Is there any way around this?
| You do it basically like you would do with a framework or module set.|
Create a folder inside your module search path, place level.monkey there.
In your editor and your game you can then import it like this:
| Sorry, I just saw that you import game from within level.monkey. So my solution does not work. |
| I guess you need to figure out what level.monkey needs from editor and game classes, and either take it out, or provide a standard interface for passing it. |
| My problem has been solved.|
In the end, I guess Monkey X handles imports better than what BlitzMax did, but I'm still used to being lazy in BlitzMax.
But is there any way to import a file from a include folder not in the same folder?
For example, I have my game in a folder called something like "projects\game\" and there's an inc folder containing my import files "projects\game\inc\" so game.monkey imports via something like
import inc.levelwhich will look in "projects\game\inc\".
But what happens if I have a folder called "tools" inside "game" that also wants to use the same inc folder "projects\game\tools\"?
I can't do
import ..\inc.levelfrom the "tools" folder.
| You could try to put them inside your "modules_ext" folder which is located in your monkey directory.|
If you use Jungle IDE you can also define an additional Module folder under Tools>>Preferences>>Monkey>>Additional Modules which could be located wherever you want.
I had the same problem a while back and relocating the modules seems to be the best what you could do. All the other things like relative paths have some drawbacks here or there which cause you trouble.
| The base directory to start from is always the main folder, so in your example above:|
Import game.inc.inc Import game.tools.inc
Would import "game/inc/inc.monkey" and "game/tools/inc.monkey"
Not sure about the ".level" extension, and if this is something you would have to include in the #TEXT_FILES directive to get it to work properly, as by default the "Import" seems to auto-append the ".monkey" to files it is importing
Sadly this does not work when multiple files share the same module folder...
| If files are in a module folder, use the foldername as the root. If they're relative to the app, use the app folder _(or nothing if they're at the same level). It's this easy. And works. |