Legacy GM Execution Error - Variable Index [0,7] out of range [1,7] [Solved]

Hello everyone! I'm having trouble with my achievement system that I can't seem to fix. I've tried a lot of different things but nothing seems to work. so I'm just going to show you my code and hopefully you can help. If your not sure what some of the code means, ask me and I will explain it :)

Error:
Code:
___________________________________________
############################################################################################
FATAL ERROR in
action number 1
of Draw Event
for object obj_achievement_control:

Push :: Execution Error - Variable Index [0,7] out of range [1,7] - -5.secretAchievement(100229,7)
 at gml_Object_obj_achievement_control_DrawEvent_1 (line 8) - if(secretAchievement[i] = 1) {
############################################################################################
Create:
Code:
globalvar numofach;
numofach = 7
//check for achievements locked/unlocked
//locked = 0 unlocked = 1
globalvar achievementU, unlockingAch, cUnlocking, secretAchievement; achievementU = 0 secretAchievement = 0

achievementU[0] = 0 secretAchievement[0] = 0
for(i = 0; i < numofach; i += 1) {
achievementU[i] = 0
secretAchievement[i] = 0
}

unlockingAch = -1
cUnlocking = -1

achievementy = 0
achy = 0

numofach = numofach+1
sc_load_achievements()

//set this for all secret achievements
secretAchievement[6] = 1
Draw:
Code:
if(room = r_achievements) {
for(i = 1; i < numofach; i += 1) {
if(i > 0) {
achievementy = 200*i
//drawing ach.
draw_sprite(spr_achievements,i,room_width/2 + 175.5,achievementy - 51)
if(achievementU[i] = 0) {
if(secretAchievement[i] = 1) {
draw_sprite(spr_locked_achievement,1,room_width/2 + 175.5,achievementy - 51)
} else {
draw_sprite(spr_locked_achievement,0,room_width/2 + 175.5,achievementy - 51)
}
}
}
}
}
Thanks for the help! :p
 
T

TimothyAllen

Guest
Its because of this line

numofach = numofach+1

You initialize your array from 0 to numofach - 1 (6), but then you increment numofach. Then you try to access your array using numofach as a limit... but you incremented numofach by one (8) so numofach -1 (7) is out of bounds.
 
Its because of this line

numofach = numofach+1

You initialize your array from 0 to numofach - 1 (6), but then you increment numofach. Then you try to access your array using numofach as a limit... but you incremented numofach by one (8) so numofach -1 (7) is out of bounds.
thank you for the help, I don't even know why I added that XD
 
Top