Importing same file to multiple separate projects

Monkey Forums/Monkey Beginners/Importing same file to multiple separate projects

Hezkore(Posted 2014) [#1]
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?


MikeHart(Posted 2014) [#2]
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:

Import yourNewFolder.level



MikeHart(Posted 2014) [#3]
Sorry, I just saw that you import game from within level.monkey. So my solution does not work.


Gerry Quinn(Posted 2014) [#4]
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.


Hezkore(Posted 2014) [#5]
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.level
which 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.level
from the "tools" folder.


Pharmhaus(Posted 2014) [#6]
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.


rIKmAN(Posted 2014) [#7]
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


Pharmhaus(Posted 2014) [#8]
@rIKmAN
Sadly this does not work when multiple files share the same module folder...


ziggy(Posted 2014) [#9]
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.