Read data from TXT

zxretrosoft

Member
Joined
Jul 1, 2017
Location
Prague, Czech Republic
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! ;)
 

magic

Active Member
3rd Party Tool Dev
Joined
Mar 5, 2018
Cerberus X:
Local a$[] = LoadString("test.txt").Split ("~n")
For Local k=0 Until a.Length()
    Print Int(a[k])
Next
 

zxretrosoft

Member
Joined
Jul 1, 2017
Location
Prague, Czech Republic
Thank you so much!
But it seems to me that he doesn't read the text file. What am I doing wrong? :rolleyes:

Cerberus X:
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
 

zxretrosoft

Member
Joined
Jul 1, 2017
Location
Prague, Czech Republic
OK, and now - where should I put the routine?

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