What causes Error running script: Index was out of range?

For help with creating games using Quest

Moderators: Pertex, Alex, sgreig, Cryophile

What causes Error running script: Index was out of range?

Postby AvecPardon » Sat Mar 17, 2012 11:55 pm

It's the very first thing that pops up in the game. I'd made some recent changes to it and now I see that error;
Error running script: Index was out of range. Must be non-negative and less than the size of the collection. Parameter name: index.

I've gone backwards, undoing just about everything I can think of that was recently changed, but that error still keeps coming up.

What usually causes this error, so that I can be more aware of what it is I'm doing with the scripting and avoid another one?
AvecPardon
 
Posts: 24
Joined: Sat Jan 21, 2012 4:24 am
Location: U.S.A

Re: What causes Error running script: Index was out of range

Postby MerchantToo » Sun Mar 18, 2012 7:17 am

Maybe you are using something like this to go through a list?

Code: Select all
item = ObjectListItem(ItemList,index)


Then you have to make sure that the value of 'index' falls into range.
The first item in a list has index 0, and the last item has ListCount(ItemList)-1, e.g.

Code: Select all
for (index, 0, ListCount(ItemList)-1, 1) {
        item = ObjectListItem(ItemList,index)
        item.bigfancyproperty = something
}
MerchantToo
 
Posts: 19
Joined: Mon Feb 06, 2012 8:48 am
Location: Nederland

Re: What causes Error running script: Index was out of range

Postby Alex » Sun Mar 18, 2012 12:58 pm

If it's not that, please attach your .aslx file to a reply here and I'll take a look for you - and also I'll be able to improve Quest to give a more helpful error message.
User avatar
Alex
Site Admin
 
Posts: 2074
Joined: Fri Jun 27, 2003 11:06 pm
Location: London, UK

Re: What causes Error running script: Index was out of range

Postby AvecPardon » Mon Mar 19, 2012 1:01 am

After taking MerchantToo's advice, I re-examined my scripting and found I put the wrong parameter in the call function at the very start of the game. I have already fixed it, but to help in making the error message a bit more understandable, I've recreated the error.

It involves a modified version of Pixie's Score library and functions, so i'll put that up as well. The initial error was that the parameter at the start script was set to 'false' when it should have been 'true' and was completely omitted in the actual InitScore function.

Hope that helps.

Score_Lib.aslx
modified score library used in System Restore
(2.2 KiB) Downloaded 23 times

System Restore with error.aslx
(137.9 KiB) Downloaded 16 times
AvecPardon
 
Posts: 24
Joined: Sat Jan 21, 2012 4:24 am
Location: U.S.A

Re: What causes Error running script: Index was out of range

Postby Alex » Mon Mar 19, 2012 10:04 am

Thanks for this, I've now updated the code for Quest 5.2 to provide a more helpful error message in situations where you don't pass the required number of parameters to a function.
User avatar
Alex
Site Admin
 
Posts: 2074
Joined: Fri Jun 27, 2003 11:06 pm
Location: London, UK


Return to Quest Forum

Who is online

Users browsing this forum: R2T1 and 0 guests