Adding Modules???

Monkey Forums/Monkey Beginners/Adding Modules???

DaveGill(Posted 2014) [#1]
HI,

I have dabbled with Monkey before and created a few things by following tutorials but now want to build something from scratch.... Well by using some modules from other people... So I downloaded a couple of modules and placed them in the Monkey folders modules folder.

But I am unable to use them when I try and do an Import.. Am I doing something really silly?


skape(Posted 2014) [#2]
What is the structure of your modules folder? What code are you trying to use to import?


Paul - Taiphoz(Posted 2014) [#3]
your Modules folder should look like this.

>Monkey\modules\mojo << the Brl Mojo module. inside that folder is the code and then its native folders.

So if you install something like diddy, or any other module, you place its folder inside modules and make sure that your module is not a folder in a folder, so for diddy for example the path should be something like, Monkey\modules\diddy\*lots of code files* and not Monkey\modules\diddy\src\*code files.*

If you downloaded a module from a repository it will often contain a load of extra stuff, in the case of diddy, the actual module is in as I recall the src folder.


Gerry Quinn(Posted 2014) [#4]
There's also a little trick Monkey has in which it looks for a file in a directory of the same name. So if there is one called modules/something/something.monkey, then "import something" will work as well as "import something.something"


Paul - Taiphoz(Posted 2014) [#5]
Import dir.file also works, some modules like my own have additional folders inside the main module folder, in my case I have my main ember module code inside modules/ember but I then also have additional folders inside the ember directory which contain more specific code like modules/ember/math/math.monkey which I import via Import ember.math.math


DaveGill(Posted 2014) [#6]
Right so I am on OSX. This is my Monkey folder.
Daves-MacBook-Pro-2:MonkeyPro76d davegill$ ls -al
total 1168
drwxr-xr-x@ 15 davegill staff 510 2 Feb 20:21 .
drwx--x--x+ 13 davegill staff 442 2 Feb 20:41 ..
-rw-r--r--@ 1 davegill staff 12292 2 Feb 21:50 .DS_Store
-rwxr-xr-x@ 1 davegill staff 71072 20 May 2013 Monkey
drwxr-xr-x@ 3 davegill staff 102 19 Nov 15:27 Monkey.app
-rwxr-xr-x@ 1 davegill staff 443904 20 May 2013 Monkey.exe
-rwxr-xr-x@ 1 davegill staff 988 10 Apr 2013 README.TXT
-rwxr-xr-x@ 1 davegill staff 55703 19 Nov 12:43 VERSIONS.TXT
drwxr-xr-x@ 15 davegill staff 510 19 Nov 15:27 bananas
drwxr-xr-x@ 26 davegill staff 884 2 Feb 20:22 bin
drwxr-xr-x@ 6 davegill staff 204 2 Feb 21:34 docs
drwxr-xr-x@ 15 davegill staff 510 2 Feb 21:50 modules
drwxr-xr-x@ 4 davegill staff 136 2 Feb 21:34 modules_ext
drwxr-xr-x@ 9 davegill staff 306 19 Nov 15:27 src
drwxr-xr-x@ 13 davegill staff 442 19 Nov 15:27 targets

And this is the modules folder
Daves-MacBook-Pro-2:modules davegill$ ls -al
total 32
drwxr-xr-x@ 15 davegill staff 510 2 Feb 21:50 .
drwxr-xr-x@ 15 davegill staff 510 2 Feb 20:21 ..
-rw-r--r--@ 1 davegill staff 12292 4 Feb 13:00 .DS_Store
drwxr-xr-x@ 8 davegill staff 272 2 Feb 21:35 autofit
drwxrwxrwx@ 9 davegill staff 306 2 Feb 21:48 box2d
drwxr-xr-x@ 28 davegill staff 952 19 Nov 15:27 brl
drwxr-xr-x@ 12 davegill staff 408 19 Nov 15:27 dom
drwxr-xr-x@ 34 davegill staff 1156 2 Feb 21:48 fantomEngine
drwxrwxrwx@ 5 davegill staff 170 2 Feb 21:48 json
drwxr-xr-x@ 22 davegill staff 748 19 Nov 15:27 mojo
drwxr-xr-x@ 14 davegill staff 476 19 Nov 15:27 monkey
drwxr-xr-x@ 14 davegill staff 476 19 Nov 15:27 opengl
drwxr-xr-x@ 5 davegill staff 170 19 Nov 15:27 os
drwxr-xr-x@ 5 davegill staff 170 19 Nov 15:27 reflection
drwxr-xr-x@ 17 davegill staff 578 19 Nov 15:27 trans

Whenever I try to import fantomEngine it is ignored...


monkeyteets(Posted 2014) [#7]
what is the contents of the fantomEngine dir? is fantomEngine.monkey directly in fantomEngine dir ?

fyi I'm on osx, and I put all my third party modules in modules_ext, makes it easy to move to new versions of monkey without impacting the default modules


DaveGill(Posted 2014) [#8]
Hi The fantomengine code is available directly in the folder...
Daves-MacBook-Pro-2:modules davegill$ cd fantomEngine/
Daves-MacBook-Pro-2:fantomEngine davegill$ ls -al
total 1016
drwxr-xr-x@ 34 davegill staff 1156 2 Feb 21:48 .
drwxr-xr-x@ 15 davegill staff 510 2 Feb 21:50 ..
-rw-r--r--@ 1 davegill staff 15364 4 Feb 13:00 .DS_Store
-rwxr-xr-x@ 1 davegill staff 19361 18 Aug 13:25 Changes.txt
-rwxr-xr-x@ 1 davegill staff 1393 18 Aug 13:25 ToDo.txt
-rwxr-xr-x@ 1 davegill staff 28323 18 Aug 13:25 cftAStar.monkey
-rwxr-xr-x@ 1 davegill staff 47211 18 Aug 13:25 cftBox2D.monkey
-rwxr-xr-x@ 1 davegill staff 84528 18 Aug 13:25 cftEngine.monkey
-rwxr-xr-x@ 1 davegill staff 7209 18 Aug 13:25 cftFont.monkey
-rwxr-xr-x@ 1 davegill staff 4879 18 Aug 13:25 cftFunctions.monkey
-rwxr-xr-x@ 1 davegill staff 5603 18 Aug 13:25 cftHighscore.monkey
-rwxr-xr-x@ 1 davegill staff 9569 18 Aug 13:25 cftImageMng.monkey
-rwxr-xr-x@ 1 davegill staff 3568 18 Aug 13:25 cftKeyMapping.monkey
-rwxr-xr-x@ 1 davegill staff 16380 18 Aug 13:25 cftLayer.monkey
-rwxr-xr-x@ 1 davegill staff 4679 18 Aug 13:25 cftLocalization.monkey
-rwxr-xr-x@ 1 davegill staff 3018 18 Aug 13:25 cftMisc.monkey
-rwxr-xr-x@ 1 davegill staff 100063 18 Aug 13:25 cftObject.monkey
-rwxr-xr-x@ 1 davegill staff 4248 18 Aug 13:25 cftRGBA.monkey
-rwxr-xr-x@ 1 davegill staff 5586 18 Aug 13:25 cftScene.monkey
-rwxr-xr-x@ 1 davegill staff 6095 18 Aug 13:25 cftSound.monkey
-rwxr-xr-x@ 1 davegill staff 5878 18 Aug 13:25 cftSpriteAtlas.monkey
-rwxr-xr-x@ 1 davegill staff 4838 18 Aug 13:25 cftSwipe.monkey
-rwxr-xr-x@ 1 davegill staff 5434 18 Aug 13:25 cftTileMap.monkey
-rwxr-xr-x@ 1 davegill staff 4590 18 Aug 13:25 cftTimer.monkey
-rwxr-xr-x@ 1 davegill staff 13281 18 Aug 13:25 cftTrans.monkey
-rwxr-xr-x@ 1 davegill staff 17034 18 Aug 13:25 cftTween.monkey
-rwxr-xr-x@ 1 davegill staff 4761 18 Aug 13:25 cftVec2D.monkey
-rwxr-xr-x@ 1 davegill staff 31540 18 Aug 13:25 cftWaypoints.monkey
drwxr-xr-x@ 21 davegill staff 714 18 Aug 13:26 docs
drwxr-xr-x@ 16 davegill staff 544 18 Aug 13:25 examples
-rwxr-xr-x@ 1 davegill staff 2484 18 Aug 13:25 fantomEngine.monkey
-rwxr-xr-x@ 1 davegill staff 1147 18 Aug 13:25 license.txt
drwxr-xr-x@ 20 davegill staff 680 18 Aug 13:26 monkeydoc
drwxr-xr-x@ 6 davegill staff 204 4 Feb 13:00 native

Am I supposed to put them in modules_ext???? I will give that a try as well.


MikeHart(Posted 2014) [#9]
Which Monkey version to you use?

Are the examples of fantomEngine running fine? Which platform did you target? Please post the error you get inside the console when you build your app.

The location of the fantomEngine is fine.


DaveGill(Posted 2014) [#10]
I am using MonkeyPro76d..
Start of the code is:-
Import mojo
Import fantomEngine
Function Main()
New Game
End
Class Game Extends App
Field eng:engine
Field player:Image
Field x:Float
Field y:Float

Method OnCreate()
player = LoadImage("boing.png")
SetUpdateRate 60
eng = New engine
Local obj0:=eng.CreateBox(200,200,220,140)
obj0.SetColor(0,0,255)
' SetVirtualDisplay 800, 480
End

And my error is:-
/Users/davegill/Documents/Harry/HarryGame.monkey<15> : Error : Type 'engine' not found


MikeHart(Posted 2014) [#11]
Change engine to ftEngine.

Strict
Import fantomEngine

Function Main:Int()
    New Game
    Return 0
End

Class Game Extends App
    Field eng:ftEngine
    Field player:Image
    Field x:Float
    Field y:Float

    Method OnCreate:Int()
        player = LoadImage("boing.png")
        SetUpdateRate 60
        eng = New ftEngine
        Local obj0:=eng.CreateBox(200,200,220,140)
        obj0.SetColor(0,0,255)
        ' SetVirtualDisplay 800, 480
        Return 0
    End
End



DaveGill(Posted 2014) [#12]
Yes.. Tried that and same error.
Import mojo
Import fantomEngine
Function Main()
New Game
End
Class Game Extends App
Field eng:ftEngine
Field player:Image
Field x:Float
Field y:Float

Method OnCreate()
player = LoadImage("boing.png")
SetUpdateRate 60
eng = New ftEngine
Local obj0:=eng.CreateBox(200,200,220,140)
obj0.SetColor(0,0,255)
' SetVirtualDisplay 800, 480
End
Error just changes to
Users/davegill/Documents/Harry/HarryGame.monkey<15> : Error : Type 'ftEngine' not found


MikeHart(Posted 2014) [#13]
I am puzzeled. Works for me fine here. Btw. I needed to change the code above to add the return types and statements to the Main function and OnCreate method. When you add Strict to the top, you need to do this. Also you don't need to import mojo extra, as fantomEngine does it itself.

So, if you have a fantomEngine folder inside your Monkey/Modules or Monkey/Modules_Ext folder, and inside you see the fantomEngine.monkey file, then I don't know what is wrong with your setup.


MikeHart(Posted 2014) [#14]
Did you made changes to the config file inside the bin folder? Could you post that please?


MikeHart(Posted 2014) [#15]
If you have placed the content from the zip folder inside your modules folder, your monkey installation folder should look like this

Monkey
  |--bananas
  |--bin
  |--docs
  |--modules
     |--box2d
     |--brl
     |--dom
     |--fantomEngine
        |--docs
        |--examples
        |--monkeydoc
        |--native
        |--Tools
        |--cftAStar.monkey
        |--...
        |--fantomEngine.monkey
        |--...



DaveGill(Posted 2014) [#16]
Hi,

First: I am very impressed with all the assistance people are giving to me.. Its great, so thanks and apologies for being a bit thick here.

Anyway yes my modules does indeed follow the same pattern as yours above. As for the config file I am assuming I need the config.macos.txt file? Which is detailed below:-

'--------------------
'Monkey modules path
'
'Can be overriden via transcc cmd line
'
MODPATH="${MONKEYDIR}/modules;${MONKEYDIR}/modules_ext"
'--------------------

'--------------------
'HTML player path.
'
'Must be set for HTML5 target support.
'
HTML_PLAYER=open -n "${MONKEYDIR}/bin/mserver_macos.app" --args
'--------------------

'--------------------
'Ant build tool path
'
'Must be set to a valid dir for ANDROID target support on Mavericks ('coz Mavericks no longer includes Ant).
'
'Ant is currently available here:
' http://ant.apache.org/bindownload.cgi
'
ANT_PATH="${HOME}/apache-ant-1.9.2"
'--------------------

'--------------------
'Flex SDK and flash player path.
'
'Must be set for FLASH target support.
'
FLEX_PATH="${HOME}/flex_sdk_4.9.1"
FLEX_PATH="${HOME}/flex_sdk_4.9"
FLEX_PATH="${HOME}/flex_sdk_4.6"
'
'for opening .swf files...monkey will use HTML_PLAYER if this is not set.
'FLASH_PLAYER="...?..."
'--------------------

'--------------------
'Android SDK and tool paths.
'
'Must be set to a valid for for ANDROID target support
'
'Android SDK
ANDROID_PATH="${HOME}/android-sdk-macosx"
'--------------------

'--------------------
'Android NDK
'
'Must be set to a valid dir for ANDROID NDK target support
'
ANDROID_NDK_PATH="${HOME}/android-ndk-r9"
'--------------------


MikeHart(Posted 2014) [#17]
Looks good. Again, which target platform did you choose to build your project on? HTML5, STDCPP, etc.?


DaveGill(Posted 2014) [#18]
Does not matter what I choose I get the same error, but I have tried IOS and HTML5. Both of which work fine when I do not try to include any other modules.
Just thought though does it matter where my own project files are and the structure of them? Does it need to be inside the Monkey folder?

I was previously using Monkey on Windows and never had any problems so this is all a bit weird.


DaveGill(Posted 2014) [#19]
Just an addition. If I open any of the examples in the fantomeEngine module folder and try and build them I get the same kind of error.. Type 'App' not found.


MikeHart(Posted 2014) [#20]
Its like it doesn't find mojo either! That is why I have asked if you can run the native examples inside the bananas folder.


DaveGill(Posted 2014) [#21]
Loaded Bananas/ferdi/snake/snake.monkey and built without a problem!


MikeHart(Posted 2014) [#22]
Sorry, I don't know anymore how I could help you. This is weird.


computercoder(Posted 2014) [#23]
@DaveGill

I run on MacOS X, and I do not need to keep my project files/folders under Monkey-X's folder structure. You only need to keep the modules you get from BRL and third parties under either modules or modules_ext.

I ONLY compile to HTML5, OUYA, or ANDROID targets, so I can help you with these targets, and if you get running on one of them, you should be able to get the others running similarly.

First, lets try this:

Change this:


To:


I have had to do the same thing to direct it to the file I needed to load when working with third party mods. It worked for me, even with my own modules.

If that DOES NOT work, then try doing my suggestions below.

I would try to simply get HTML5 running first. In order to do this, let's do the following:

1) Create a fresh new project and folder. Anywhere is fine, I would recommend a folder outside of Monkey-X's folder structure.

2) Build something without any third party modules

3) Add a third party module, such as Ignition, Diddy, fantomEngine, or the like and compile it against HTML5. Please note that you may need to grant permission on Mac to allow the web server to execute and each of the bin files needed by Monkey-X on Mac OS X 10.9.x

Also worth noting: If you previously compiled your application/game in an older version of Monkey-X, and updated to a newer version, you will need to DELETE the BUILD folder for any project you did this with FIRST. Let me re-iterate, you just need to delete the BUILD folder, not the source code. After this is done, you may proceed to build and execute your app/game and it should execute.

Hope this helps!