Best(any) way to avoid identifier clashes
Monkey Forums/Monkey Programming/Best(any) way to avoid identifier clashes
| ||
Hi guys. I'm making a framework for my next project and I'm finding that names I want to use are already in use by Monkey (Image, Node etc). I was wondering if there's a way to avoid these clashes, or at least quality which you want to use? I sort of thought that if I had a file called import library.Node I could go: field m_node:library.Node but that doesn't work. Thanks |
| ||
These names are used by mojo and not monkey itself. If you setup on mojo the only way would be to choose other names. Maybe Sprite instead of Images if you know what I mean. |
| ||
I could go: field m_node:library.Node that does work. make sure library is the name of you monkey file and its in your game directory or in the modules folder within a directory called library. |
| ||
Hi Jesse. That's what I was doing. I have a directory for my framework, lets call it "framework". I then goimport framework.node (This has a class called Node in it) Class SomeClass Field m_field:framework.Node End That does not work for me, I still get the error saying Node is already defined in map. |
| ||
Hi, Try node.Node This is because only the last part of the import 'path' is actually added as a scope, eg: import mojo.graphics actually only imports a 'graphics' scope. Another thing you can do is... Alias Node=node.Node ...and then be able to use Node directly. Or, you could add the following to framework.monkey... Import node Alias Node=node.Node ...and then you'd be able to go... Import framework Global node:framework.Node |
| ||
Ahh I see Mark, thanks! BTW: Is Alias only available in a certain version of Monkey because all I get when trying to use it is "Syntax error - expecting declaration" if I go Alias Node = node.Node right after the class definition. Also, Alias is not highlighted for me in the editor. I'm running the latest version, or so I think. |
| ||
Alias should appear at the top of the source code document, in the same area where you put your import statements. That's why it's not working after the class declaration. I would suggest to fully qualify classes instead of using Alias, as Alias gets populated too and IMHO can cause clashes for the names you're aliasing when importing the documents. while it's better than nothing, I suggest using the modulename.ClassName approach as the best solution. |