Multiple file project (SOLVED)
Monkey Forums/Monkey Programming/Multiple file project (SOLVED)
| ||
I'm creating a game project and there's several classes on a single file, I was wondering in putting each class in different files, but how can I include this file in main file ? |
| ||
When you have split classes into separate files,you can easy import those. Some Example: file: class_a.monkey class A method SomeMethod() Print "Some Method" end method end class file: main_file.monkey import class_a function Main:int() local a:A=new A() a.SomeMethod() end function |
| ||
Place your classes in to separate files and use Import at the very top of your source files (just like what you do with mojo) e.g. Import myclassfile If you have classes that are closely related like those that make up mojo ( have a look in the modules directory), then make a file that is just contains nothing but Imports and then you can just add that file to the top of you source files. |
| ||
Do this.... Main.monkey import player import alien import level class mygame.... import Main class player .... etc ... Monkey handles cyclical imports so as long as you import main into any new file it will import everything main imports ie your whole project. |
| ||
What vbnz (and dawlane and taiphoz) said, but I would recommend using indentation in your code to make it easier to read. |
| ||
Thanks a lot SOLVED! |