0 votes

Hi guys, I recently made a variant of type Array<Array<Dictionary>> and stored some data in it. Later I saved the data in a file and when I read back the data, the data was of type Array but I couldn't cast the type to Array<Array<Dictionary>>.

=====

Pseudo-code:

class demo { 
    private Array<Array<Dictionary>> arr;

    public void method() {
        arr = some data;
        ...
        file.write(JSON.Print(arr));
        ...
        content = file.read();
        //result is of type Array
        result = JSON.Parse(content).Result;
        //crash, InvalidCastException
        arr = (Array<Array<Dictionary>>)result;
    }
}

I have tried a few things,

Array arr;
arr = result.Result;
((Array)arr[index])[index] = foo;

seems to be a workaround.

But can I directly cast via like arr = (Array<Array<Dictionary>>)result; ?

Godot version v3.5.1 stable
in Engine by (12 points)

Please log in or register to answer this question.

Welcome to Godot Engine Q&A, where you can ask questions and receive answers from other members of the community.

Please make sure to read Frequently asked questions and How to use this Q&A? before posting your first questions.
Social login is currently unavailable. If you've previously logged in with a Facebook or GitHub account, use the I forgot my password link in the login box to set a password for your account. If you still can't access your account, send an email to [email protected] with your username.