Can I import .monkey files

Monkey Forums/Monkey Programming/Can I import .monkey files

Tri|Ga|De(Posted 2011) [#1]
Is it possible to import another .monkey file in my own .monkey file?


Perturbatio(Posted 2011) [#2]
have you tried it? (I'm guessing include is what you want rather than import)


Tri|Ga|De(Posted 2011) [#3]
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)


Perturbatio(Posted 2011) [#4]
Hmm... it's causing an error for me too.


skid(Posted 2011) [#5]
Extern is for linking with other languages not for sharing code between monkey files.


Tri|Ga|De(Posted 2011) [#6]
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


Tri|Ga|De(Posted 2011) [#7]
How do I call the methods in my main file?


DruggedBunny(Posted 2011) [#8]
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.


Tri|Ga|De(Posted 2011) [#9]
I tried that but it still will not regonize the dt method in my main


Beaker(Posted 2011) [#10]
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.


Tri|Ga|De(Posted 2011) [#11]
Nope!
Says NClass tester not found