ID:155722
 
Code:
//Found obvious errors in my code i wrote to try to give an example of the problem... maybe you an answer without it?


runtime error: list index out of bounds
proc name: testproc (/obj/testguy/proc/testproc)
usr: the cloudy (/mob)
src: the testguy (/obj/testguy)
call stack:
the testguy (/obj/testguy): testproc()
the testguy (/obj/testguy): Click(the grass (2,5,1) (/turf/grass), "mapwindow.map", "icon-x=16;icon-y=6;left=1;scre...")


Problem description: I get this out of bounds error a lot (runtime) im not sure what it means and if i understood it better I could debug it

Right now I've written an extensive amount of code on a work around to the following problem: If you add mob's to a list, how do you access the mob in a specific spot in the list and access that mob's variables?

What im doing is adding the names of the mobs to a list, comparing the names to mobs in view (or world) to locate the mob I want modified, then accessing its variables. If only...

lista[1].name = "billy" worked... :(

//If you know something about the specific mob you're looking for, like the key or the specific name...
var/mob/M
for(var/mob/m in list)
if() //put some code here to narrow down the mob you're looking for
M=m
break
if(!M) return //cancel if the mob isn't found at all
//now apply whatever code you'd like afterward.
In response to Bravo1
Bravo1 wrote:
> //If you know something about the specific mob you're looking for, like the key or the specific name...
> var/mob/M
> for(var/mob/m in list)
> if() //put some code here to narrow down the mob you're looking for
> M=m
> break
> if(!M) return //cancel if the mob isn't found at all
> //now apply whatever code you'd like afterward.
>


The return you provided will end the procedure, which isn't the desired effect.

OP: It's difficult to say what the exact issue is because of the lack of source code - at least provide the snippet of the lines surrounding (and including) the code so we can further serve you. Generally, an index out of bounds implies in a list[n], you are searching list[n+k], which does not exist, assuming n is the maximum integer and k is an integer > 0. As well, this can occur when dealing with text strings that also have bounds, or when BYOND is trying to process a number outside its limits (though I doubt this is the issue you are experiencing).
In response to Nal_rA
It'll only end the procedure if it doesn't return the mob they're looking for. If it does then it'll continue to carry out any code under if(!M) return. You don't want to get a runtime error by trying to change the variables of null.
The "list index out of bounds" error tells you that the index you are seeking from the list is out of the bounds of the list.

For example:
var/list/something = list("foo", "bar")

mob/verb/Test()
usr << something[3] // but something only has 2 elements!
In response to Hiead
Hiead wrote:
The "list index out of bounds" error tells you that the index you are seeking from the list is out of the bounds of the list.

For example:
var/list/something = list("foo", "bar")
>
> mob/verb/Test()
> usr << something[3] // but something only has 2 elements!


Thanks i think THIS is the issue i've been experiencing. My lists are determined by the number of mobs in view of the object but the code that checks for the one I'm looking for goes beyond the lists length. Got it.