Windows Weird error when reading array

R

RylanStylin

Guest
wierd error.pngwierderror.png
When the code tries to read global.boss_array[boss_array_place] in the instance_create_layer statement, the game crashes with that code. I've set the following things in the object's create event.
global.boss_array = array_create(6,[obj_0,obj_1,obj_2,obj_3,obj_4,obj_5]);
boss_array_place = 0;

I dont understand why this is happening. I have tried and tried to get this to work properly but it just doesnt want to. I know for sure that the problem is the array because if i put a obj_1 in instead of global.boss_array[boss_array_place]; it works just fine. It's just the array, but everything is in order. PLEASE SEND HELP
 

Attachments

Last edited by a moderator:
Wait... I've never seen that syntax of setting up an array before. global.boss_array = (6,[obj_0,obj_1obj_2,obj_3,obj_4,obj_5]); What does the "(6," and ")" do? I think I might not understand how that works because I would just do it like this:
global.boss_array = [obj_0,obj_1,obj_2,obj_3,obj_4,obj_5];
 

Xer0botXer0

Senpai
The error is expecting a number, perhaps a positive integer, if obj_x doesn't exist you'll be putting -4 in as a parameter.
 

samspade

Member
In my experience, error messages are never wrong, so if GM says you gave it an array, I would assume that is what happened. I would inspect the it in the debugger, and see what the value is in more detail.

Also as PhallicSpleen pointed out, this global.boss_array = (6,[obj_0,obj_1obj_2,obj_3,obj_4,obj_5]); is not valid syntax and wouldn't compile. What does the code actually look like there? As a side note, if those outer parenthesis were brackets, you would have nested arrays and the first position would itself be an array so if boss_array_place equals 1, you would then be passing it an array rather than an object id.
 
R

RylanStylin

Guest
Thanks to all you guys who responded. The problem was indeed how I was setting up my array, @PhallicSpleen. I was using the GML reference for array_create, which specifies array_create(size,[value]);
@telepathe that was just a typo in the post.
 

rytan451

Member
According to the manual, when you use array_create(size, [value]), then it creates an array with the given size, with each element filled with value. In your case, the value you're giving it is [obj_0,obj_1obj_2,obj_3,obj_4,obj_5], so your array would look like this:
JavaScript:
[
  [obj_0,obj_1obj_2,obj_3,obj_4,obj_5],
  [obj_0,obj_1obj_2,obj_3,obj_4,obj_5],
  [obj_0,obj_1obj_2,obj_3,obj_4,obj_5],
  [obj_0,obj_1obj_2,obj_3,obj_4,obj_5],
  [obj_0,obj_1obj_2,obj_3,obj_4,obj_5],
  [obj_0,obj_1obj_2,obj_3,obj_4,obj_5]
]
For future reference, in the manual, parameters in [square brackets] are optional parameters; they can be omitted. The manual having parameters in square brackets doesn't mean that you should put your parameter in square brackets!

You should probably have your code like this:

GML:
global.boss_array = [obj_0, obj_1, obj_2, obj_3, obj_4, obj_5];
 
R

RylanStylin

Guest
According to the manual, when you use array_create(size, [value]), then it creates an array with the given size, with each element filled with value. In your case, the value you're giving it is [obj_0,obj_1obj_2,obj_3,obj_4,obj_5], so your array would look like this:
JavaScript:
[
  [obj_0,obj_1obj_2,obj_3,obj_4,obj_5],
  [obj_0,obj_1obj_2,obj_3,obj_4,obj_5],
  [obj_0,obj_1obj_2,obj_3,obj_4,obj_5],
  [obj_0,obj_1obj_2,obj_3,obj_4,obj_5],
  [obj_0,obj_1obj_2,obj_3,obj_4,obj_5],
  [obj_0,obj_1obj_2,obj_3,obj_4,obj_5]
]
For future reference, in the manual, parameters in [square brackets] are optional parameters; they can be omitted. The manual having parameters in square brackets doesn't mean that you should put your parameter in square brackets!

You should probably have your code like this:

GML:
global.boss_array = [obj_0, obj_1, obj_2, obj_3, obj_4, obj_5];
very interesting. Thank you, this clears alot up.
 
Top