Skip to main content

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

[Solved] Weird array behaviour?

A topic by baku created Jul 17, 2019 Views: 318 Replies: 1
Viewing posts 1 to 2
(1 edit)

I noticed something weird with arrays, and I'm not sure what's up. Whether it's a bug, whether I'm not understanding something about how arrays work, or whatever, idk.. 馃


Setup:

  • Create a new GMS2 project
  • Import GMLive.gml, place obj_gmlive in the room
  • Create a new object, place it in the room
  • Create event of the object:
if (live_call()) return live_result;
a[0] = "foo";
b = a;
b[0] = "bar";
show_debug_message("a[0] = " + a[0] + ", b[0] = " + b[0]);
  • Step event of the object:
if keyboard_check_pressed(vk_space) room_restart();


What happens:

  • If live_enabled is set to 0 (i.e. live reloading not enabled), a[0] = foo, b[0] = bar shows up in the output console when the game is run, as well as whenever spacebar is pressed to restart the room. This is the behaviour I am expecting.
  • If live_enabled is set to 1, a[0] = foo, b[0] = bar shows up in the output console when the game is run, but whenever the room is restarted, it now somehow becomes a[0] = bar, b[0] = bar, as if the array is suddenly getting passed by reference or something?
Developer

As the documentation notes, copy-on-write behaviour is not supported - since ownership data is completely hidden from GML side, GMLive has no way of simulating this feature while keeping compatible with base behaviour.