Indie game storeFree gamesFun gamesHorror games
Game developmentAssetsComics
SalesBundles
Jobs
Tags

GMLive.gml

Livecoding for GameMaker: Studio / GameMaker Studio 2 · By YellowAfterlife

[Fixed in 1.0.48+] Unsure How To Correct Error: "Cannot ensure array type for value."

A topic by Quixottic created Mar 23, 2021 Views: 359 Replies: 3
Viewing posts 1 to 4
(1 edit)

Hello there! Fairly new to GMLive, and it has been blowing my mind! Great work and thank you, first and foremost!

Now I'm guessing this is a user error and not an issue with GMLive, but I haven't figured out how to fix it after searching through all the documentation, forums, and broader internet. For that, I apologize when this is something obvious that I'm missing. 

When working with data that is in 2D and 3D arrays, I have been receiving this error message: 

obj_test_pause_background:Draw_64[L24,c18] Cannot ensure array type for value. Use [@index] if it does not need allocation or create it explicitly.

L24, c18 is very first use of the double bracket array call: "array_name[i][0]". Now I'm guessing I'm using the live call function incorrectly. This is what I have been doing in most other places outside of scripts with arguments:

if (live_call()) return live_result;

Is there some other way I'm supposed to be calling the object:DrawGUI if the data is coming out of an array? I'm not sure how the error is suggesting I use @index, nor can I find anywhere in the documentation that makes this clear to me either. 

All the rest of the code and live updating works fine if I just drop the 2D or 3D array structure and use standard variables, so that's why I'm betting I'm the idiot who's screwing it up. 

Any assistance you can provide would be awesome! Thank you so! 

Developer

Your line must be something like

array_name[i][k] = val

which looks innocent but is executed as

if <is not set>(array_name) || !is_array(array_name) array_name = [];
var tmp;
if (i >= array_length(array_name) || !is_array(array_name[i])) {
    tmp = [];
    array_name[@i] = tmp;
} else tmp = array_name[i];
tmp[@k] = val;

Changing it to array_name[@i][@k] = val; would fix it. Using legacy [i, k] syntax might also work since I had that hard-coded as an exception from usual rules before.

I intend to rewrite how GMLive handles this but it’s a moderate amount of work since you can similarly do map[?key][ind] = val, list[|i][k] = val, and so on, and it will store the freshly made array in the data structure in each case.

Amazing! Huge thank you for the detailed explanation! It's always nice to be proven right that I'm the idiot! ;)  Really appreciate the quick response, and this puts me back in business with the amazing live coding you've created! Time for an @ party!  \o/

Developer

This is finally fixed in 1.0.48 - GMLive now supports arbitrarily long chains of array accessors for writes.