Public functions

Jimmy

Active member
3rd Party Module Dev
Tutorial Author
Joined
Jan 2, 2020
Messages
922
What's the prefferable way in Cerberus when you want to offload your main and move some functions
into a external.cxs laying beside the main.cxs (not inside modules).
 

dawlane

Well-known member
CX Code Contributor
Joined
Jun 21, 2017
Messages
856
Not sure what you mean. All Cerberus source files are modules and imported the same way regardless, but the general convention is to have the program entry function coupled with the core mojo class in the same source file. Additional sub classes are imported, but here are some rules.

All classes, function,etc in sources are public, unless the Private keyword is declared somewhere.
The private keyword only takes affect at the module scope level and not the class scope. This means that the same source file, all classes and functions are public regardless if anything was declared private inside or outside a class.
 
Last edited:

Phil7

Administrator
CX Code Contributor
3rd Party Tool Dev
Joined
Jun 26, 2017
Messages
644
Not sure what you mean
Same here. Maybe you can ask a bit more specifically. With your question a lot of things come to mind regarding the structure of a cerberus project:
Folder structure, file naming, file size, interdependencies, class and/or function modules, modules_ext folder, native files etc.
 

MikeHart

Administrator
Joined
Jun 19, 2017
Messages
3,167
What's the prefferable way in Cerberus when you want to offload your main and move some functions
into a external.cxs laying beside the main.cxs (not inside modules).
To each their own I would say. I have projects where everything is in one file. Then I have projects where every class is in their own file. I have projects where functions are in their own file. It is up to you how you want to structure your own code.
 

dawlane

Well-known member
CX Code Contributor
Joined
Jun 21, 2017
Messages
856
I have projects where everything is in one file. Then I have projects where every class is in their own file.
For me. It depends on the size of the project. The more complex, the more modular the directory tree and file hierarchy should be for easy code locating.
 

Jimmy

Active member
3rd Party Module Dev
Tutorial Author
Joined
Jan 2, 2020
Messages
922
Thanks. Okay I'm starting to get a lot of functions recently and I want to lay them off into a separate functions.cxs and somehow include it into my main?

EDIT Sorry, what I mean is, should imported .cxs files be inside the data folder or should all cxs be in one place?
 
Last edited:

Jimmy

Active member
3rd Party Module Dev
Tutorial Author
Joined
Jan 2, 2020
Messages
922
Besides functions, I also created a lot of methods inside the main class (Class Game Extends App) right now.

How can you drag them out a file?
 

Phil7

Administrator
CX Code Contributor
3rd Party Tool Dev
Joined
Jun 26, 2017
Messages
644
should imported .cxs files be inside the data folder or should all cxs be in one place?
They should not be in teh data folder. There should only reside the resources of your app and they are copied to stay available at runtime. On the other hand your .cxs files are only needed at compiletime and they all result in the executable file afterwards.
If you have a lot of interdependency in your source you could for example have a imports.cxs file inside a "imports" folder next to your yourmainfile.cxs. imports.cxs only consists of the import directives for all the common modules you use. And you can put them all inside the "imports" folder.

I also created a lot of methods inside the main class (Class Game Extends App) right now.

How can you drag them out a file?
I don't think you can, but you could think about an other way of structuring your code in this case. For larger projects I prefer an Game class that is as short and as readable as possible, so you can easily grasp what the main funcionality is about.
 

Jimmy

Active member
3rd Party Module Dev
Tutorial Author
Joined
Jan 2, 2020
Messages
922
You can't seem to have several classes that extends from App.

So I converted methods into functions (example below) which only gives me "Error: Type'Canvas' not found" as it wants to have App-related types like the canvas?

Function explosion:Int(grassland:Canvas,x:Int,y:Int,a:Int,b:Int:a)
...
Return 0
End
 

Phil7

Administrator
CX Code Contributor
3rd Party Tool Dev
Joined
Jun 26, 2017
Messages
644
That's what I mean by high interdependency. If you do the "imports.cxs" thing, you can write "Import imports" in all files that need access to those things. In your case you would have to have "import mojo2" inside imports.cxs.
 

Jimmy

Active member
3rd Party Module Dev
Tutorial Author
Joined
Jan 2, 2020
Messages
922
This works out pretty good. Thanks! (y)
 
Top Bottom