• 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

Read data from TXT

zxretrosoft

Member
Joined
Jul 1, 2017
Messages
32
Hello friends,
I have one little question, please.

How to make the shortest routine, for READ data from TXT file?

I have in TXT list:
012346
244565
125475
...

And now, I'd like to get these values into the fields:
a[1]=012346
a[2]=244565
a[3]=125475
...

Thank you in advance! ;)
 
Cerberus:
Local a$[] = LoadString("test.txt").Split ("~n")
For Local k=0 Until a.Length()
    Print Int(a[k])
Next
 
Thank you so much!
But it seems to me that he doesn't read the text file. What am I doing wrong? :rolleyes:

Cerberus:
Import mojo

Function Main()
    New Game()
End

Class Game Extends App

    'summary:The OnCreate Method is called when mojo has been initialized and the application has been successfully created.
    Method OnCreate()
    
        'Set how many times per second the game should update and render itself
        SetUpdateRate(60)
    
    End
    
    'summary: This method is automatically called when the application's update timer ticks.
    Method OnUpdate()
        
    End
    
    'summary: This method is automatically called when the application should render itself, such as when the application first starts, or following an OnUpdate call.
    Method OnRender()
        Cls()
        
    End

    'summary: This method is called instead of OnRender when the application should render itself, but there are still resources such as images or sounds in the process of being loaded.
    Method OnLoading()
    
        Local a:String[] = LoadString("C:\Hry\file.txt").Split("~n")
        For Local k = 0 Until a.Length()
            Print Int(a[k])
        Next
        
    End
    
    'summary: This method is called when the application's device window size changes.
    Method OnResize()
        
    End
    
    '#REGION Code to handle susped status of the game goes here
    
    'summary: OnSuspend is called when your application is about to be suspended.
    Method OnSuspend()
    
    End
    
    'summary: OnResume is called when your application is made active again after having been in a suspended state.
    Method OnResume()
        
    End   
    '#END REGION
    
    '#REGION Code to handle game closing goes here:
    
    'summary: This method is called when the application's 'close' button is pressed.
    Method OnClose()
        Super.OnClose()
    End

    'summary:This method is called when the application's 'back' button is pressed.
    Method OnBack()
        Super.OnBack()
    End
    
    '#END REGION

End
 
Use loadstring from the os module.
Cerberus:
import os
os.LoadString(...)
 
LoadString() only read files inside data folder
 
OK, and now - where should I put the routine?

Cerberus:
        Local a:String[] = os.LoadString("C:\Hry\file.txt").Split("~n")
        For Local k = 0 Until a.Length()
            Print Int(a[k])
        Next
 
Back
Top Bottom