0

code

Hi, I'm pretty new to gamemaker and I'm trying to set a variable (global.b1) to the first value of "global.level_data". For example, global.b1 will be set to mimic the blue outline of "global.level_data"'s first value, which is 0. Can anyone tell me how to do this?

1 Answers1

1

If I look at it correctly, you want to get the first value of an array

I think this should suffice:

 global.level_data = [0,0]
 global.b1 = global.level_data[0];

It may look confusing if you're not familiar with how arrays work, but the [0] represents the first value of the array (which happens to be 0 as well). The count of arrays also starts with 0 instead of 1.

For further understanding about arrays, I recommend reading this: https://manual.yoyogames.com/GameMaker_Language/GML_Overview/Arrays.htm

And as a side note: if you're creating new variables, the values in that variable will usually not update it's original form (e.g. changing the value global.b1 will not change the value in global.level_data[0] unless you set that yourself).

If you prefer the latter, then I think you're better off using global.level_data[0] for getting and setting directly

Steven
  • 1,996
  • 3
  • 22
  • 33