Windows Variable out of range error within quiz game using ds list

Hi,
I have searched within the community for the answer to no avail, it just hasn't been clear to me. I'm building a quote trivia game with 1600 questions yet the error keeps flagging the 66th question within a ds list.

global.question[66] = "I am afraid I am a constant disappointment to my party. The fact of the matter is, the longer I am president the less of a party man I seem to become."
global.option1[66] = "William Taft"
global.option2[66] = "Benjamin Harris"
global.option3[66] = "Warren Harding"
global.option4[66] = "William Clinton"
global.hint[66] = "US Presidents - The 27th president of the United States."
global.answer[66] = 1 //correct answer;
------------------------------------------------------------------------------------------------

The error:
############################################################################################
FATAL ERROR in
action number 1
of Create Event
for object obj_add_from_code:
Push :: Execution Error - Variable Index [0,66] out of range [1,66] - -5.question(100005,66)
at gml_Object_obj_add_from_code_Create_0 (line 530) - global.question[66] = "I am afraid I am a constant disappointment to my party. The fact of the matter is, the longer I am president the less of a party man I seem to become."
############################################################################################
stack frame is
gml_Object_obj_add_from_code_Create_0 (line 530)
called from - gml_Object_obj_from_code_Mouse_4 (line 3) - instance_create_layer(x,y,"instances",obj_add_from_code);

------------------------------------------------------------------------------------------------------------------------------------------------------

Create Event:
The top of my ds list:
global.current_question=1
global.number_of_questions=1600;
global.correct=0;
----------------------------------------------------------------------
Bottom of my ds list:
/// The list and shuffle
global.quote_list=ds_list_create();
for (var i=1; i< global.number_of_questions; i+=1)
{
ds_list_add(global.quote_list,i);
}
ds_list_shuffle(global.quote_list);
room_goto(room_quiz);

****Also, when a quiz game such as this is published, are the questions automatically randomized with each play of the game?

Thank you in advance.
Matt
 

Slyddar

Member
My suggestion is you are starting your list at 1, so are leaving the first list entry empty. When you sort them, they are getting jumbled up and list entry 0 is ending up at position 66. When outputting you are getting the error. It's always the same order as you are not running randomize initially. Start the list at zero, and just add 1 to the position for the question number, and that might fix it.
 

FrostyCat

Member
Learn to count from 0. Your code involving data structures and arrays will never come out right if you keep starting from 1.

For example, this from your code:
GML:
for (var i=1; i< global.number_of_questions; i+=1)
{
    ds_list_add(global.quote_list, i);
}
Do you know how many times ds_list_add() gets to run here? Answer: global.number_of_questions-1
 
Thank you FrostyCat,
For your question to me, are you saying that it will run negative -1 times, so it won't run? Is it for (var i=0; I<global.number_of_questions; I=0)

I'm now triggering an out of range error on this, it's within a left mouse click object:

/// @description Create Object To Load From Code
instance_create_layer(x,y,"instances",obj_add_from_code);
with (obj_from_code) instance_destroy();
 

Nocturne

Friendly Tyrant
Forum Staff
Admin
Moderator
What Frosty is saying is that your current code will return one less than the global count value. Simply change the loop to start at 0 not 1. EG: If the global count is 60, you need to count from 0 to 59, and not 1 to 59 which is how you currently have it. So:

GML:
for (var i=0; i< global.number_of_questions; i+=1;)
 
Top