#Array references changed and broke the game

9 messages · Page 1 of 1 (latest)

chilly elbow
#

;Hello, has something changed with array referencing? (Or at least I think it's called that)

I have a script that gets an array from another object, and I do that using
var chatHistory = Obj_GameSystem.GameSystemChatHistory;
Later in that script, Obj_GameSystem.GameSystemChatHistory is modified, using the data in var chatHistory.

The intended result is that var chatHistory stays as an old copy of the other variable, and for months, it worked like that.. until recently.
Now, var chatHistory seems to reference the variable it was meant to only copy.
This breaks my chat system and inventory system, but I've managed to fix the chat system using
var chatHistory = variable_clone(Obj_GameSystem.GameSystemChatHistory);
.,..i kinda fear having to comb through all my code for the places i need to put "variable_clone" into, so i'd like to know first if this change in array-referencing behavior is something i did, or if it was part of a gamemaker update
(Update: Despite toggling "Enable Copy On Write Behaviour for Arrays", the game's still broken from unintentional array references)

eager terrace
chilly elbow
# eager terrace there was a change months ago (if not years ago), to where variables store refer...

Oh thanks for showing that option! i didn't know it existed
,though it doesn't seem to be fixing anything when i toggle that option

here's a gif from an older version of my game, it shows duplication of items, chat text, and pickup text
https://gyazo.com/a98e7703987c5f9bad7a6abe5a431253
i'm really not sure why array referencing has changed in my game, or why the legacy option doesn't work,.,.. i don't think this older game version had this bug before, either

#

ima switch this post's tag to "head-scratcher" (it was originally meant to be a quick question, as i thought this could be fixed by an option i missed)

#

Array references changed and broke the game

bright delta
# chilly elbow ;Hello, has something changed with array referencing? (Or at least I think it's ...

The latest version 2023.8 changed how lots of things are referenced.

Assets And Data Structures Now Use Typed References
The runtime has now been changed so that it uses type-specific handles rather than the old integer indices to identify resources and structures
Accordingly, functions now confirm that the argument you have passed them is actually the correct type they were expecting and will show an appropriate error when the argument being passed in is incorrect
For example: var ds = ds_map_create(); ds_list_add(ds,16); will now always throw an error, as you are trying to add a value into a map using a function intended for lists (previously, the results would vary according to whether there was a list which had the same index number)
This affects DS structs, Objects, Sprites, Sounds, Rooms, Backgrounds (tilemaps), Paths, Scripts, Fonts, Timelines, Tiles (tilesets), Shaders, Sequences, AnimCurves, Instances and Particle Systems, so please be aware that your code may now need fixes before it will work in 2023.8 if you have actually had invalid function calls all along and old versions didn’t tell you
is_handle() has been added that will identify if the passed variable is a handle or not
All the …_exists() functions will permit being passed invalid references without throwing an error so that they can correctly return that the asset does not exist
And also be aware that all …_getname() functions will also still allow being passed invalid references without throwing an error, in order to maintain compatibility with popular third-party frameworks
#

it doesn't specifically mention arrays, but it mentions data structures in general

#

so if you were doing some weird math or arithmetic with id's before, its not gonna work anymore

#

the same thing will happen with all assets moving forward, starting with 2023.10