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

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(, file.size());
Vector< String > map = mystr.Split('\n');

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

#include "Scripts/Utilities/"
void Start()
    File@ f = File("/home/s/test.txt", FILE_READ);
    Print("file size: " + String(f.get_size()));
    Print("current position: " + String(f.get_position()));
String patchInstructions = "";

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.

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);
        {   String str = f.ReadString();
                         f.Close     ();
            return str.Split('\n');
        return Array<String>();
1 Like

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) + "]";

How about with the latest from the master branch?

From here I took the file download
And everything worked well here.

I have corrected for this.
here I took the file download

Build by C::B MSYS GCC 10.3: → Size Urho3DPlayer.exe == 23 Mb → Size Urho3DPlayer.exe == 17Mb

1 Like