SOLVED Array out of bounds error

got the error while executing my code for my card game
code error:

___________________________________________
############################################################################################
FATAL ERROR in
action number 1
of Step Event0
for object obj_deck:

Push :: Execution Error - Variable Index [0,12] out of range [1,12] - -1.deck(100006,12)
at gml_Script_scr_shuffle_deck (line 12) - if(deck > 0 && deck[temp_1] > 0){
############################################################################################
--------------------------------------------------------------------------------------------
stack frame is
gml_Script_scr_shuffle_deck (line 12)
called from - gml_Object_obj_deck_Step_0 (line 10) - scr_shuffle_deck();

My script:
var numShuffle = 100;

//condition to not shuffle my deck
if(deckCount == 0){
return;
}

for(j = 0; j < numShuffle; j++){
//shuffle action
for(i = 0; i < deckCount; i++){
var temp_1 = irandom_range(2, deckCount);
if(deck > 0 && deck[temp_1] > 0){
var temp_2 = deck;
deck = deck[temp_1];
deck[temp_1] = temp_2;
}
}
}

return;

My create event:

deck_buffer_x = .4;
deck_buffer_y = .4;

deck_count = 0;
deck_pointer = 0;
for(i = 0; i < 3; i++){
deck = 1;
}


deck[i++] = 1;
deck[i++] = 2;
deck[i++] = 3;
deck[i++] = 1;
deck[i++] = 2;
deck[i++] = 3;
deck[i++] = 1;
deck[i++] = 2;
deck[i++] = 3;



deckCount = i;

#macro CARDMAX 3

scr_init_sprite_array();

i = 0;

My draw event:
draw_set_color(c_black);
draw_text_transformed(1000, 1000, string(deck), 10, 10, 1);

for(i = 0; i < deckCount; i++){
card_sprite = spr_cardback;
if(face_up){
card_sprite = sprite_array[deck];
}
if(deck > 0){
draw_sprite(card_sprite, -1, deck_x+deck_buffer_x*i, deck_y-deck_buffer_y*i);
}
}

My step event:
if(keyboard_check_released(vk_up)){
deck_buffer_x = 190;
face_up = 1;
}
if(keyboard_check_released(vk_down)){
deck_buffer_x = .4;
face_up = 0;
}
if(keyboard_check_released(vk_space)){
scr_shuffle_deck();
}

I just followed a tutorial and verified if I didn't make a mistake but I can't find where I failed, pls help me
 

Nocturne

Friendly Tyrant
Forum Staff
Admin
Moderator
GML:
var temp_1 = irandom_range(2, deckCount);

// Should probably be:

var temp_1 = irandom_range(2, deckCount - 1);
irandom_range will return a value up to AND including the maximum value.
 
Top