• 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

Reflection

Rich

Well-known member
CX Code Contributor
3rd Party Module Dev
Tutorial Author
3rd Party Tool Dev
Joined
Sep 9, 2017
Messages
451
Hi
Any reflection in cerberusX?
How would I loop through fields in a class? Is this possible?
ta
Rich
 
It is the same like in Monkey X. But I have no experience in what you want to do. But I heard that it is possible.
 
I also never used it, but could remember something in the tutorial videos of smalltimeoutlaws. Maybe this video shows what you are looking for. I think exacly that in about the middle of the video.
 
Thats perfect!
I found the REFLECTION_FILTER in the docs but with no information

thank you everyone
 
Last edited:
TIP 1 for reflection:
If you need access to vars within your Game class
Code:
Function Main:Int()
New Game()
Return 0
End Function

Class Game Extends App
end

your reflection filter needs to look like (game is the name of the file with your code, not your class name)
Code:
#REFLECTION_FILTER="game|mojo.app"

If you need access to Image vars within your code then the reflection code needs to look like this
Code:
#REFLECTION_FILTER="game|mojo.app|mojo.graphics"
 
TIP 2 reflection getting the fields

This is an example. This will set all strings to "hello world", all floats to 4.2,all ints to 42 and load an image into all images.
Not very practical.

Code:
' get class
Local c:ClassInfo = GetClass("Game")
' get fields
Local fields:FieldInfo[] = c.GetFields(False)

i=0
While i<fields.Length()
  Print "var name="+fields[i].Name
  Print "var type="+fields[i].Type.Name

  Select fields[i].Type.Name
  case "cerberus.boxes.StringObject"
    fields[i].SetValue(Self,BoxString(String("hello world")))
  case "cerberus.boxes.FloatObject"
    fields[i].SetValue(Self,BoxFloat(Float(4.2)))
  case "cerberus.boxes.IntObject"
    fields[i].SetValue(Self,BoxInt(Int(42)))
  case "mojo.graphics.Image"
    fields[i].SetValue(Self,LoadImage("image.png"))
  end
  i=i+1
Wend

These videos (thanks to Phil7) show a better example of using a text console to set vars within a game.
 
Last edited:
Back
Top Bottom