• Hey Guest! Ever feel like entering a Game Jam, but the time limit is always too much pressure? We get it... You lead a hectic life and dedicating 3 whole days to make a game just doesn't work for you! So, why not enter the GMC SLOW JAM? Take your time! Kick back and make your game over 4 months! Interested? Then just click here!

Defined irandom_range for 1D array, is picking 2D array values, and out of range numbers.

GML:
randomize();
var j = irandom_range(0, array_length_1d(activities) - 1);
global.vActivity = activities[j];
alarm[0] = room_speed * 10;
Very simple code here. I have a 1D array called activities, it goes up till like [15]. Whenever, my alarm countdown ends, I want to randomly choose a value from the array, hence: irandom_range(0, array_length_1d(activities) - 1);

Except whenever the alarm for the code activates, I get:
help.png

I don't understand why it's picking such a crazy number when I set the range. Not only that, but it's two numbers, as if it were a 2D array. What am I doing wrong here?
 

TsukaYuriko

☄️
Forum Staff
Moderator
100040 is the ID of the instance that is being processed, -214783648 is something internal that you don't need to concern yourself with.

What's really happening here is that you didn't declare activities before this code runs, hence "not set before reading it".
 

TailBit

Member
Shouldn't you use array_length in 2.3+ .. still, array_length_1d shouldn't be broken even if it is Deprecated.
 
100040 is the ID of the instance that is being processed, -214783648 is something internal that you don't need to concern yourself with.

What's really happening here is that you didn't declare activities before this code runs, hence "not set before reading it".
Thanks! Accidentally made it global before and forgot to change.
 
Top