• 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

Print statement

Wingnut

Well-known member
3rd Party Module Dev
Tutorial Author
Joined
Jan 2, 2020
Messages
1,414
I use the terminal a lot when debugging and would like to know if there's a way to skip newlines in the Print statement?
In some old languages you could do Print "not new line just yet";

Cerberus:
Strict
Import mojo2

Function Main:Int()
    New myClass       
    Return 0
End

Class myClass Extends App

    Field canvas:Canvas
    
    Method OnCreate:Int()
        SetUpdateRate 0               
        canvas = New Canvas
        
        ' --------------------------------------------
        ' Input
        '
        ' Ideas for next version :
        ' variablename.Real = #
        ' variablename.Imag = #

        ' Multiplies two complex numbers in the terminal
        '
        ' a + bi *  c + di
        ' e..g (10 + 5i) * (10 + 5i) = =75 + 100i
        
        Local a:Float = 10 ' real 
        Local b:Float = 5 ' imaginary
        '
        Local c:Float = 10 ' real
        Local d:Float = 5 ' imaginary

        Print "The answer is :" ' Avoiding appending strings and put in one Print
        Print String((a * c) - (b * d))
        Local imaginary:Float = ((a * d) + (b * c))
        Local imag:String = String(Abs(imaginary)) + "i"
        If imaginary < 0 Then Print "-" + imag
        If imaginary > 0 Then Print "+" + imag
        ' --------------------------------------------
        
        Return 0
    End
    
    Method OnRender:Int()
        canvas.Clear
        canvas.Flush
        Return 0
    End
    
End
 
Not sure what you are trying to do.
When you use the print function. It automatically appends a newline.
If you want to control how a string is display, use:
~n for newline
~t for tab
~q for a double quote.
See the documentation on escape characters.
 
I'm trying to Print multiple things on the same line without merging a string first.

The current code above outputs this:

The answer is :
75
+100i


I want this (wo merging strings):
The answer is : 75+100i
 
So it's more about ignoring newline.. Is there a "minus newline" escapecode?
 
I just needed a temporary fix (line 37 I commented out the newline) so now I can debug a lot of information in a streamlined fashion.


debug.png
 
Why not write your own purpose built code to output information that you want?
Print is just a function.
 
Back
Top Bottom