Modpath error - import=UnitType, existing=Unit

Trust

New Member
Joined
Mar 8, 2019
Likes
2
#1
Hello guys,

im new to Cerberus X and i am really confused why i get the following errors:

Modpath error - import=UnitType, existing=Unit
Modpath error - import=UnitTypeTable, existing=Unit


My filestructure looks like this:
main.cxs -> imports game
game.cxs -> imports mojo2, Unit, UnitType
Unit.cxs -> /
UnitType.cxs -> /
UnitTypeTable.cxs -> /

can somebody tell me whats wrong here?
 

Trust

New Member
Joined
Mar 8, 2019
Likes
2
#3
This is the code:

main.cxs
Cerberus X:
Strict

Import Class_Game


Function Main:Int()
    New Game
    Return 0
End
Class_Game.cxs
Cerberus X:
Strict

Import mojo2

Import Class_Unit
Import Class_UnitType
Import Class_UnitTypeTable


Class Game Extends App
...
...
...
Class_Unit.cxs
Cerberus X:
Import Class_UnitType


#REM
    Represents an instance of any unit in the game.
#END

Class Unit
...
...
...
Class_UnitType.cxs
Cerberus X:
#REM
    A general unit definition that could turn out to be anything
#END

Class UnitType
...
...
...
Class_UnitTypeTable.cxs
Cerberus X:
Import Class_UnitType

#REM
    The unit type table stores the unit types the game can have.
    It also determines the attributes of each unit type.
    The unit type table determines the balance of the game.
#END

Class UnitTypeTable
...
...
...
Thats the import structure so far...
 

dawlane

Active Member
CX Code Contributor
Joined
Jun 21, 2017
Likes
198
#4
I've managed to recreate the problem.
You haven't made it very clear on how your file hierarchy is structured on disk. It's not clear what you mean by Unit.cxs -> /

A correct structure should look like this:
ProjectRoot/
main.cxs -> import sources.game​
sources/
game.cxs -> imports mojo2, unit, unittype​
unit.cxs​
unittype.cxs​

Note: sources becomes part of the name space for the module, so if you have for example two functions with the same name, but are completely different you must use the name space for that function you wish to call.

In case you do not already know, a name space is a way to access source files, classes and function with the same name. It is not recommended to have two files with the same name in the same project as the Import statement cannot differentiate between multiple imports of same named files even with a name space specifier.
e.g. Will throw an error for duplicate files.
Import game
Import sources.game

If you intend to make any module available to all your software. You should place it in the Cerberus\modules_ext directory in their own unique directories (name space).

Tip: All file and directory names should be lower case to avoid issues with file paths when considering cross platform.
 
Last edited:

Trust

New Member
Joined
Mar 8, 2019
Likes
2
#6
Thanks for the help.
It was in fact the wrong file structure. Didn't realize that the folder name becomes a part of the namespace (like in python).
Thanks to all of you for the help.
 

dawlane

Active Member
CX Code Contributor
Joined
Jun 21, 2017
Likes
198
#7
Ehmmm, that is your opinion.
With the error he was getting and figuring out from his first post what he was trying to accomplish. The directory structure I showed would have been the most easiest solution to solve the problem.

The project directory can look any way that you want it to, as long as you read the docs and remember to use name spacing for sub directories or creating a default import with the same name as the directory that imports all other files within. Just like what you see in the mojo module.
 
Top Bottom