How do I create modules?

Monkey Forums/Monkey Programming/How do I create modules?

Supertino(Posted 2011) [#1]
How do I make my own modules - BMAX style?

Looking at the mojo and monkey modules I just created a folder called dave within the modules folder, then created the following;

Function Hello()
	Print "Hello World"
End Function


saved it as helloworld.monkey

I then tried to run the following source code.

Import mojo
Import dave

Function Main()
	Hello()
End Function


It fails as it cannot find module dave.

I knew it would not be that easy so can any one tell me what I need to do. Does not seem to be a bmk.exe equivalent.


Warpy(Posted 2011) [#2]
Save it as 'dave.monkey'

Or, if you don't change the filename, you need to Import dave.helloworld


Supertino(Posted 2011) [#3]
O.o fast reply

Yeah If I have put the file "helloworld.monkey" in the same location as my main file and import it

Import mojo
Import helloworld.monkey

Function Main()
	Hello()
End Function


it will work.

But any way I can have a folder and import all .monkey files within that folder with;

import dave


or specific modules in the folder with;

import dave.helloworld
import dave.othermod


I notice the mojo and monkey folders have a native folder within with compiled source so I guess that is the answer but sadly above my skill level =D


xAD(Posted 2011) [#4]
If you look in the folder mojo, there is a mojo.monkey file which imports app, graphics, etc.

So, I would guess in your dave folder you should have a dave.monkey file which imports helloworld, othermod, etc.

(Of course, as this topic died seven months ago, you probably already figured it out or gave up)