Skip to main content

Indie game storeFree gamesFun gamesHorror games
Game developmentAssetsComics
SalesBundles
Jobs
TagsGame Engines

GMEdit

A high-end code editor for all things GameMaker · By YellowAfterlife

Odd Warning? Can't cast to array<?> for assignment, but only after adding a struct property definition using the [$ ] notation

A topic by tuskgame created Oct 24, 2022 Views: 152 Replies: 2
Viewing posts 1 to 2

I have a scenario like this:

function TestStruct() constructor {
    prop1 = 1;
    prop2 = 2;
}

function Wrapper() constructor {
    contents = {
        a : new TestStruct(),
        b : new TestStruct()
    }
}

and if I add some extra definitions to the contents struct anywhere in the project (like below, where a custom property is passed via a constructor argument)

function Wrapper(myCustomProperty) constructor {
    contents = {
        a : new TestStruct(),
        b : new TestStruct()
    }

    contents[$ myCustomProperty] = new TestStruct();
}

I get a warning at the closing brace of the contents struct which says:

Can't cast { a: TestStruct, b: TestStruct } to array<?> for assignment

It is less of a major inconvenience, but more so an oddity that leaves me with a warning for what appears to me to be correct code.

Developer(+1)

I have now pushed a hotfix for this.

Wonderful, thanks so much for your dedication to creating and maintaining tools for the community