Archive 17/01/2023.

Angelscript: Loading a char file into a 2D array: how?

xlat

All is well - documentation on urho is sea.
Hmm, and I’m drowning in it …

The task seems to be simple and it is like this:
You need to stupidly load your format (albeit text) the ENTIRE file into a string.

The task is a little more difficult:
Something like this:

File file("my.txt");
String mystr[file.size()];
file.Read(mystr.data(), file.size());
Vector< String > map = mystr.Split('\n');

How to write this in Angelscript correctly to make it work?

tarzeron
#include "Scripts/Utilities/Sample.as"
void Start()
{
    Print("//////////////////");
    File@ f = File("/home/s/test.txt", FILE_READ);
    Print("file size: " + String(f.get_size()));
    //Print(String(ReadInt));
    Print(f.ReadLine());
    Print("current position: " + String(f.get_position()));
    Print(f.ReadString());
    f.Close();
    engine.Exit();
}
String patchInstructions = "";
Modanung

Welcome to the forums! :confetti_ball: :slightly_smiling_face:

Threads in the Support section can be marked as solved. You could move this one there and mark @tarzeron’s post as the solution (after refreshing) to increase his solutions count to 2. It also adds a check mark to the thread’s title.

xlat

Thanks a lot,
I made such a test class,
Thanks to your hint:

class Gamemap
{   String name = "test.txt";
    Array<String> m;
    
    uint r = 0;
    uint c = 0;
    
    String load()
    {   m = from_file("data/!my-files/map_test.txt");
    
        if(m.length == 0) return "ERROR: \"map_test.txt\" FILE!";
        
        r = m   .length;
        c = m[0].length;
        
        return String("Стенд - 001: map[") + String(r) + "][" + String(c) + "]";
    }
    
    Array<String> from_file(String name)
    {   
        File@ f = File(name, FILE_READ);
        if(f.open)
        {   String str = f.ReadString();
                         f.Close     ();
            return str.Split('\n');
        }
        return Array<String>();
    }
}
xlat

This does not work in the Urho 1.8 Alfa version:

To make it work again, I did this:

    String s = String("Stend - 001: map[");
return     s + String(r) + "][" + String(c) + "]";
Modanung

How about with the latest from the master branch?

xlat

From here I took the file download Urho3D-master.zip
And everything worked well here.

I have corrected for this.
here I took the file download Urho3D-1.8-ALPHA.zip

Build by C::B MSYS GCC 10.3:
Urho3D-master.zip → Size Urho3DPlayer.exe == 23 Mb
Urho3D-1.8-ALPHA.zip → Size Urho3DPlayer.exe == 17Mb