// code continues, and will compile with no errors when package is not used
I’m new to programming in general, and I was under the impression that the directory that the file is located in is on the left of the dot and a name we want to assign to our project goes on the right. However, when I try to compile in neko, using the terminal, I get this error:
The package should be in lower case, and is (basically) the directory structure.
For the file src/engine/utils/Helper.hx you’d have package src.engine.utils;.
If you wanted to use that file as main file you’d do haxe -main src.engine.utils.Main (...).
The only time the package isn’t exactly the directory structure is if you use classpaths,
by default haxe looks into the current directory for your code, but can also look in more.
For instance it’s often made that the src/ directory is added as classpath, by doing haxe -cp src/ (...),
in that case the file src/engine/utils/Helper.hx would have package engine.utils;, and be used by haxe -cp src/ -main engines.utils.Helper (...).
In terminal:
Case 1:
At “home/myAccount” level: haxe -main src.engine.utils.Main -neko main.n
output: Invalid commandline class : src.engine.utils.Main should be Main
Case 2:
cd to ~/src/engine/utils haxe -main src.engine.utils.Main -neko main.n
output: Type not found : src.engine.utils.Main
Am I getting errors because it is looking for other files in the directory (that don’t exist yet) and it’s not finding them?
Often what is done is you have a Main class in the topmost directory of your code folder, e.g. “src/Main.hx” which acts as the entry point. It would just have a package; line with no path. Then if you had other classes in subfolders you would use import statements to get them, and those classes would have the longer package statement at the top.
If you really want the Main entry point to be in the subfolders, you would want to use a .hxml file with the compiler instead of just a Main.hx file. Instructions for that are here. Does that help?