• Dear Cerberus X User!

    As we prepare to transition the forum ownership from Mike to Phil (TripleHead GmbH), we need your explicit consent to transfer your user data in accordance with our amended Terms and Rules in order to be compliant with data protection laws.

    Important: If you accept the amended Terms and Rules, you agree to the transfer of your user data to the future forum owner!

    Please read the new Terms and Rules below, check the box to agree, and click "Accept" to continue enjoying your Cerberus X Forum experience. The deadline for consent is April 5, 2024.

    Do not accept the amended Terms and Rules if you do not wish your personal data to be transferred to the future forum owner!

    Accepting ensures:

    - Continued access to your account with a short break for the actual transfer.

    - Retention of your data under the same terms.

    Without consent:

    - You don't have further access to your forum user account.

    - Your account and personal data will be deleted after April 5, 2024.

    - Public posts remain, but usernames indicating real identity will be anonymized. If you disagree with a fictitious name you have the option to contact us so we can find a name that is acceptable to you.

    We hope to keep you in our community and see you on the forum soon!

    All the best

    Your Cerberus X Team

Greetings I am a new user...

I try to explain about your issue regarding default folder and some preset function for game loop.

CerberusX is a compiler tool chain. This is some of it design philosophy that makes what it is:

- Create code once and able to translete to many program language. Then ask the language to compile execution binary like exe,apk or any output of that language. That why CerberusX need thing like Java, Android Studio, GCC and so on. Actually it translete your code to those language and ask for it to compile. So this basicaly good, one code can produce and run on any platform provided it has a trans for it (And you can create one yourself for another language that you want). Because of this nature, CerberusX need to standardise what all those language need and come out with in between solution. As a result OnCreate OnRender OnUpdate is apply because it suite for translete to many modern language out there.

- Another factor is CerberusX is object orientated (OO). This choice has been made by Mark on the beginning. I guess because all those main platform language like java, javascript, c++, c# ( that he want to be major target) is good in OO. Beside, OO is modern language and many library use it. Making a tool for android or ios for example (mobile app), we must allow support for In-app- purchase for example, or Admob avertisment, and all those library is in OO to be implimented. So he desided the CerbetusX is OO. Because of this you need to code in OO and learn to do your stuff in OO ways.

- Any core library created suggested (if possible) to be able to translete to any target. If it unique to certain target only it should not be in core library. The purpose is to maintain CX flexibility. So internal library normaly basic.
But if you need a library for certain target (In your case a zip) you can create one using extern language that you target or find other people module. So far that I know, no one create zip module yet.

That basicaly CerberusX and what it does. I hope this help you on your study and make a good choice for your purpose.
 
About GLOBAL problem, could you post in full. I cannot see what going on.
I assume you split yor code into several file. You use import (like include in other language - to organize code in chunk of files). This potentially the problem.

I think this global in another file. As far as i know global is local to it file scope.
 
Please post a small project and the error message. When you use TED, it does point you to the error.
If you use 3rd party code editors, then please take the issue to its creators.
I used Jungle IDE.
 
About GLOBAL problem, could you post in full. I cannot see what going on.
I assume you split yor code into several file. You use import (like include in other language - to organize code in chunk of files). This potentially the problem.

I think this global in another file. As far as i know global is local to it file scope.
Well,
This is the project:

The Project.png

This is the "main.cxs"

Import mojo
Import guiBasic
Import load_data
Import init_gui_theme


Global MainScreen:Gui
Global MyButton:Gui
Global Main_Menu:Gui
Global Main_Menu_Adventure_New:Gui
Global Atlas_Theme:Image <===LOOK I AM HERE AS GLOBAL
Global Fantasy_Theme:Image
Global Futuristic_Theme:Image
Global Windows_Theme:Image


Function Main()

'SetUpdateRate(60)
New Game

End


Class Game Extends App

Method OnCreate()
SetUpdateRate(60)

MainScreen = Gui.CreateScreen()
MyButton = Gui.CreateButton(10, 10, 120, 25, "MyButton", MainScreen)
Main_Menu = Gui.CreateMenu("Adventure", MainScreen)
Main_Menu_Adventure_New = Gui.CreateMenuItem("New", Main_Menu, 0, 0)
Init_Gui_Theme()

End Method


Method OnUpdate()
Gui.Update()

If KeyHit(KEY_ESCAPE)

'You end the program like the classic "End"
EndApp

EndIf


End Method

Method OnRender()
Cls(200, 000, 000)
Gui.Draw()
SetColor(255, 255, 255)
DrawText("Some text", 250, 50, 0, 0)

End Method

End Class

This is the "Init_Gui_Theme.cxs"

Import mojo
Import guiBasic


Function Init_Gui_Theme()


'Atlas_Theme = LoadImage("Atlas.png")
Atlas_Theme = LoadImage("fantasy.png")
Gui.SetTheme(Atlas_Theme)
Gui.SetFonts("titlefont.txt", "normalfont.txt", "normalfontinv.txt")

'Fantasy_Theme = LoadImage("fantasy.png")
'Gui.SetTheme(Fantasy_Theme)
'Gui.SetFonts("fantasytitle.txt", "fantasynormal.txt", "fantasynormalinv.txt")

'Futuristic_Theme = LoadImage("futuristic.png")
'Gui.SetTheme(Futuristic_Theme)
'Gui.SetFonts("DigitalTitle.txt", "Digital1.txt", "Digital2.txt")

'Windows_Theme = LoadImage("windows.png")
'Gui.SetTheme(LoadImage("windows.png"))
'Gui.SetFonts("tahomabold.txt", "tahoma.txt", "tahoma.txt")


End
There is the Atlas_Theme image variable that will load the "fantasy.png" (The files exist as well).
The variable Atlas_Theme was defined at the "main.cxs" as Global variable.
After compile....
Error.png

But it should.
 
This is a compile time error.

CX compile from top to bottom, on line 4 found this:

Import init_gui_theme

CX go into that file and phrase your code line by line and found this:

Atlas_Theme = LoadImage("fantasy.png")
(in your Init_Gui_Theme function)

At this line so far CX didn't found any declaration for Atlas_Theme. So it flag that compile error

Solution:

declare global before enter that function:

Global Atlas_Theme:Image
Function Init_Gui_Theme() ...


Then no need to declare in main file anymore. If you do, it will duplicate. Base on CX scope, if duplicate it will access this main file variable as prority. whenever Atlas_Theme is call it will access the variable declare in this main.cxs. To actually access your variable in init_gui_theme file, you then need to use

init_gui_theme.Atlas_Theme

as the name.

more info on import is here:
https://www.cerberus-x.com/cxDocs/Programming_Language%20reference.html#modules
 
Last edited:
This is a compile time error.

CX compile from top to bottom, on line 4 found this:

Import init_gui_theme

CX go into that file and phrase your code line by line and found this:

Atlas_Theme = LoadImage("fantasy.png")
(in your Init_Gui_Theme function)

At this line so far CX didn't found any declaration for Atlas_Theme. So it flag that compile error

Solution:

declare global before enter that function:

Global Atlas_Theme:Image
Function Init_Gui_Theme() ...


Then no need to declare in main file anymore. If you do, it will duplicate. Base on CX scope, if duplicate it will access this main file variable as prority. whenever Atlas_Theme is call it will access the variable declare in this main.cxs. To actually access your variable in init_gui_theme file, you then need to use

init_gui_theme.Atlas_Theme

as the name.

more info on import is here:
https://www.cerberus-x.com/cxDocs/Programming_Language%20reference.html#modules
The Global variabe was defined outside the functions I know about this. If I will define some variable as Global outside of any scope it should be visible in any scope. (Usually they are defined at the top of the program after the import commands. BlitzMax already does this. But here I was defined the variable in the main file outside of any scope (At the top of the source code) and it suppose to be visible and in other source files in the entire project. But they are not visible. If I will redefine them they will defined only in the particular source file without present the duplicate definition error.

I did another experiment. I defined one Global variable at the beginning of the program inside the "main.cxs" with name var1:int as an integer type.
In the main function I gave it a value: var1 = 5
In the memory I have one variable with name "var1" defined as global with the value = 5.
Inside the Init_Gui_Theme() function and inside the "Init_Gui_Theme.cxs" source code file the Init_Gui_Theme() function exists.
At the top of the source code I defined another one Global variable with name "var2" and is gave it a value = 3
First as we know when importing the source code at the beginning of the program all the variables and everything at least that not exist inside any function is executed. All the variable definitions with the mojo and guiBasic module.

When the Init_Gui_Theme() function will be called from the OnCreate() method inside the game class which was called from the main function, the var1 was defined from the "main.cxs" source code and the var2 was defined from the "Init_Gui_Theme.cxs", because was exist outside of any scope (Meaning any function or any loop or any operation).
When I call the Init_Gui_Theme() function, I have a code that sets the var2 the value of 3 and after this I add the value of var2 to var1.

var1 = var1 + var2
Now I should have variable with name var1 than has a value = 8.
But the var1 is not defined in this source code file but was defined in the "main.cxs" as global and it should already being in the memory.
Error.png

I believe it is a compiler bug.
All Global variables are getting forgotten when you change a source code and you will need to define everything everywhere again.
If I will define variables with same names many times scattered inside my source code files, I should have duplicated definition errors. But I am not. If you see in the screenshot above the var1 is not purple it is black (Because the compiler forgotten it) and var2 is purple (Because was defined in this source code). So because it remembers only the var2 that was defined in this source and forgets the other I see it as black.
Also if we assume the codes wasn't executed yet and the variables weren't added in the memory yet. All the source codes were imported at the beginning and all the contents that exist outside of any scope (Functions, operations, classes etc) should uploaded in the memory.
 
Last edited:
I did and another experiment.
I defined both variables inside the "Init_Gui_Theme.cxs"
And I did the mathematical operation.

var1 = var1 + var2

This is the "main.cxs"
Import mojo
Import guiBasic
Import load_data
Import init_gui_theme


Global MainScreen:Gui
Global MyButton:Gui
Global Main_Menu:Gui
Global Main_Menu_Adventure_New:Gui
Global Atlas_Theme:Image
Global Fantasy_Theme:Image
Global Futuristic_Theme:Image
Global Windows_Theme:Image

Global var1:int

Function Main()

var1 = 5

'SetUpdateRate(60)
New Game

End


Class Game Extends App

Method OnCreate()
SetUpdateRate(60)

MainScreen = Gui.CreateScreen()
MyButton = Gui.CreateButton(10, 10, 120, 25, "MyButton", MainScreen)
Main_Menu = Gui.CreateMenu("Adventure", MainScreen)
Main_Menu_Adventure_New = Gui.CreateMenuItem("New", Main_Menu, 0, 0)
Init_Gui_Theme()


End Method


Method OnUpdate()
Gui.Update()

If KeyHit(KEY_ESCAPE)

'You end the program like the classic "End"
EndApp

EndIf


End Method

Method OnRender()
Cls(200, 000, 000)
Gui.Draw()
SetColor(255, 255, 255)
SetBlend(AlphaBlend)
SetAlpha(0.5)
DrawText("Math:" + var1, 250, 50, 0, 0)

End Method

End Class

I defined the var1.
I get it a value var1=5
I called the function: Init_Gui_Theme()
Inside the function I gave a new value to var2=3
I executed the mathematical operation

var1 = var1 + var2

The function was finished and the program returned at the end of the OnCreate() method and continued down.
Until it arrived OnRender() method to draw the gui and print and the var1 in a text.
Then I see that var1 has the value 5 and not 8. The var1 was forgotten when returned from the Init_Gui_Theme() because in the "main.cxs" the
var2 wasn't defined but as I explained earlier it should because importing all the source codes all the variables or any code will be executed outside the scopes.

I did and another experiment. I defined everything everywhere. Logically the compiler wasn't present any undefined error. But is forgetting the values of the variables that exist in other source code files of the project. It happens something like when they get defined they are erased.

There is something wrong here.
 
Your opinion. Definitely not ours. And I am glad not the opinion of my company that uses this language extensively and has major success with it. Trust me, there is nothing wrong. Plus you don’t read the docs. Or don’t understand them. Magic has told you how globals work.
Just a hint for your problem. Define your globals inside one file and import that file everywhere you need them.
If you take your time and study the translated code, you might get what module scope means.

And another hint. Save your time and use a different language. CX is not for you. Stick with Blitzmax.
 
Then I see that var1 has the value 5 and not 8
I think you forgot to delete Global var1:Int in your main.cxs

I simplify your code and I got output 8 as expected
Cerberus:
'main.cxs
Import mojo
Import load_data
Import init_gui_theme
Function Main()
    var1 = 5
    New Game
End
Class Game Extends App
    Method OnCreate()
        SetUpdateRate(60)
        Init_Gui_Theme()
    End Method
    Method OnUpdate()
    End Method
    Method OnRender()
        DrawText("Math:" + var1, 250, 50, 0, 0)
    End Method
End Class

Cerberus:
'init_gui_theme.cxs
Import mojo
Global var2:Int
Global var1:Int
Function Init_Gui_Theme()
    var2=3
    var1 = var1+var2
End
 
In this version I try to show you code problem with duplicate global
Cerberus:
'main.cxs
Import mojo
Import load_data
Import init_gui_theme

Global var1:Int '<----here duplicate declaration

Function Main()
    var1 = 5
    New Game
End

Class Game Extends App
    Method OnCreate()
        SetUpdateRate(60)
        Init_Gui_Theme()
    End Method
    Method OnUpdate()
    End Method
    Method OnRender()
        DrawText("Math:" + var1, 250, 50, 0, 0)
    End Method
End Class
Cerberus:
Import mojo
'init_gui_theme.cxs
Global var2:Int
Global var1:Int

Function Init_Gui_Theme()
    var2=3
    var1 = var1+var2
End

If I set Global var1:Int in in main.cxs also, then why the math give answer 5? you might ask.
It is because there are 2 var1 in your code. Both at different memory address.
According to CX scope, when you call var1, CX will refer to var1 in main.cxs not in init_gui_theme.cxs
When duplicate var exist, CX didn't report compile error like some language, but it pick the one base on it scope rule.
This is powerful and a standard method in many advance language like C++. This is more powerful actually. The scope is nested and more structured.

For example in CX:
Cerberus:
For Local k=1 To 2
    Print "<--forloop 1"
    Print "var k ="+k
    For Local k=1 To 2
        Print "   <--forloop 2"
        Print "   var k ="+k
    next
next
You can see how var k is use in nested scope.

This only example how nested scope in CX. So to reflect the above example with your global problem is like this:
Global var is global until you declare a new one with the same name, CX will give prority to the one on it file. You still can access global from other file by using a 'dotted' module path like this:
Cerberus:
'main.cxs
Import mojo
Import load_data
Import init_gui_theme

Global var1:Int '<----here duplicate declaration

Function Main()
    init_gui_theme.var1 = 5
    New Game
End

Class Game Extends App
    Method OnCreate()
        SetUpdateRate(60)
        Init_Gui_Theme()
    End Method
    Method OnUpdate()
    End Method
    Method OnRender()
        DrawText("Math:" + init_gui_theme.var1, 250, 50, 0, 0)
    End Method
End Class
 
Last edited:
The examples are not explain how to make the Global var1 to be Global in any source code and scope. Visible everywhere.
If I want to change the value of var1 in main.cxs do I will call it from init_gui_theme.cxs with init_gui_theme.var1=5.
According what you said. I will create one separated source code file with all the variables inside with name variables.cxs and let's say if I want lots of variables I will define them all in variables.cxs and then I will call the everywhere with variables.var1 = 5 or variables.var2 = "Something" or variables.va3 = True
Can I do the same with data types?

There will be a variables.cxs
Global Var1:int
Global Var2:string
Global Var3:bool
And I will call them from everywhere like this.

variables.Var1 = 5
variables.Var2 = "Hello World"
variables.Var3 = True

How the data types are defined? And data types with arrays?
 
All Cerberus source files are treaded as individual modules. So remember, where a module is mentioned, it's a source file.
All global variables and constant variables created in a file have local module scope. In other words they have local file scope. This means that all code in that module can access only those variables in that module.

To try to make it easier to follow the concept of module scope we have two files; one called myimport and the other called mycode.
The module myimport has a global variable defined as myglobal, but mycode also has a global variable myglobal defined.
The module mycode will only see it's variable myglobal, but mycode also needs to see the variable myglobal defined in myimport.
When mycode imports myimport. It cannot see the variable myglobal in myimport to access it. For mycode to access the variable myglobal in myimport, it needs to use module scope. This is the modules name and variable separated by a scope operator. A scope operator is a dot, also know as a period, or a stop mark.

The module myimport.cxs
Cerberus:
Global myglobal:= "myimport global"
Global myglobal2:= "myimport myglobal 2"

The module mycode.cxs
Cerberus:
Import myimport

Global myglobal:= "mycode myglobal"

Function Main:Int()
    Print "Access myimport myglobal: " + myimport.myglobal
    Print "Access myimport myglobal2: " + myglobal2                ' Not hidden by mycode, so doesn't need the module scope operation
    Print "Access mycode myglobal: " + myglobal                    ' Belongs to this module, so no need for the module scope operation.
    Return 0
End

In addition to module scope. Each module has what's known as path scope. When you import a module, it could be in a different folder, so the scope operator also doubles as a file path separator. e.g.
Import brl.json
Meaning import the json file in the brl directory.

Using global variables everywhere is not a very good idea, nor is it a good idea to use the same variable name twice. It can make code very messy and hard to follow.
How the data types are defined? And data types with arrays?
In side Functions and Class Method you use:
Code:
Local variable:DATATYPE or Local variable:= value
Local variable:DATATYPE[]
See here.
 
Last edited:
The examples are not explain how to make the Global var1 to be Global in any source code and scope. Visible everywhere.
It is visible as long as you import it. But if you declare another one (with the same name) in your file, then it is not. CX will use the one that you newly declare. If you want to access the import one, you need to use the 'dotted' module path then

I will create one separated source code file with all the variables inside with name variables.cxs
You should not organize your code like that. If you want to split code, do it base on it functional purpose. Basicaly the idea is all the variable and function related to it functionality should stay in one place. Limit or avoid too much dependent of the outside. This actually leads to object orentated basic concept. That another topic already.
 
Back
Top Bottom