简体   繁体   中英

Get value in variable

代码

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?

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 (eg 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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM