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

AvecPardon
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?

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

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.

for (index, 0, ListCount(ItemList)-1, 1) {
item = ObjectListItem(ItemList,index)
item.bigfancyproperty = something
}

Alex
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.

AvecPardon
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.



Alex
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.

This topic is now closed. Topics are closed after 60 days of inactivity.

Support

Forums