ID:264895
 
Code:
mob
proc
Check_Objective(atom/A)
if(istype(A, /mob/monster))
for(var/obj/Questholder/Q in src.Questlog)
var/killcount = 0
if(!Q.completed && Q.quest_type == "Kill")
var/i = 1
for(i = 1;i <= Q.kill_target.len; i++)
var/killed = Q.kill_num[i]
var/tokill = Q.kill_amount[i] //this line does the same, no error
if(tokill == killed)
killcount++
if(A.type == Q.kill_target[i])
if(killed < tokill)
killed++
Q.kill_num[i] = killed
src << output("<font color = yellow>[A] [killed]/[tokill]</font>","spam")
if(tokill == killed)
killcount++
if(killcount == Q.kill_target.len)
src << output("<font color = yellow>[Q] Completed!</font>","spam")
Q.completed = 1

if(istype(A, /obj))
for(var/obj/Questholder/Q in src.Questlog)
var/collect = 0
if(!Q.completed && Q.quest_type == "Collect")
var/i = 1
for(i = 1; i < Q.collect_target.len; i++)
var/H = Q.collect_target[i]
var/J = Q.collect_num[i] // ERROR LINE
for(var/obj/K in src.contents)
if(K.type == H)
if(K.count >= J)
if(K.count == J && A.type == H)
usr << output("<font color = yellow>[K] [K.count]/[J]</font>","spam")
collect++
else if(A.type == H)
usr << output("<font color = yellow>[K] [K.count]/[J]</font>","spam")
if(collect == Q.collect_target.len)
usr << output("<font color = yellow>[Q] completed!</font>","spam")
Q.completed = 1

obj
Questholder
Reconstruction
collect_target = list(/obj/item/Alchemy/Orb_of_Gales, /obj/item/weapon/Adamantite_Rod)
collect_num = list(1,1)
It_is_Elementary
kill_target = list(/mob/monster/Flame_Head, /mob/monster/Lava_Golem)
kill_amount = list(5,3)
kill_num = list(0,0)


In my quest system, I utilize lists to hold the types of items or monsters that you need to collect or kill in order to complete the quests. Now then, the above code that handles collection type quests (where it checks the atom as an obj type) used to work without a problem. Now, all of a sudden it stopped working with no changes, giving the below runtime error.

runtime error: list index out of bounds
proc name: Check Objective (/mob/proc/Check_Objective)
source file: Quests.dm,33
usr: Asch (/mob/player)
src: Asch (/mob/player)
call stack:
Asch (/mob/player): Check Objective(Adamantite Rod (/obj/item/weapon/Adamantite_Rod))
Asch (/mob/player): Pickup(Adamantite Rod (/obj/item/weapon/Adamantite_Rod))
Pick Up Item (/obj/Spell_HUD/Pick_Up_Item): Click(null, "pane1.mainmap", "icon-x=14;icon-y=16;left=1;scr...")


What baffles me, though, is that the part of the code where the it checks for the mob type, it uses exactly the same code for filling the variable in the exact same manner and it does NOT have an error. Similar code is used to show progress in the quest log, and it does not have an error either. Even when showing the progress of a collection type quest.
...What line is line 33?
In response to Super Saiyan X
I marked it with a comment. I'll make it more noticeable I guess.
Stick a few debugging messages in there - what's the value of i, what's the length of collect_num, what is the contents of collect_num.

I suspect you'll find that collect_num is getting out of sync with collect_target somehow - do you have any other code that manipulates that list?
In response to Jp
I honestly have no idea what's going on. Now, all of a sudden it's working perfectly again. Without making any changes. Perhaps it's a BYOND bug that only occurs under certain conditions?

Also, the only code I have that manipulates these lists only accesses the data for use, but never directly uses the data inside. It assigns what it finds to another variable, like the above code. I know this exact code functions properly, as it was up until this afternoon. And all other instances of this exact same code worked as well, such as showing progress in the quest log, which needs to access these lists to show what you have compared to what you need. It was properly getting values there.
In response to Pyro_dragons
Chances are it's a rare bug in your code, not in BYOND. Just because it hasn't broken now/before doesn't mean it works - just means it didn't break.

I'd double-triple-quadruple check that there is nowhere where you are actually changing those lists. Do a search.

If that's definitely a no-go, I'd investigate whether or not those lists are ever initialised to the wrong size.

EDIT: Also I notice that the collect quest loop uses < for the termination condition, not <=, which it probably should be.
In response to Jp
I've checked multiple times and ensured that none of these key lists are being changed at any time, and they aren't. I'll have to do some investigating and see if I can't catch an instance where the list is not being initialized properly, but I have nothing in regards to that as of now. Thanks you for your help, though.

EDIT: Also I notice that the collect quest loop uses < for the termination condition, not <=, which it probably should be.

That was a mistake lol. Part of my debugging just to check something and I forgot to switch it back to <= before posting it here. The error occurred with <= not <. Course, if BYOND lists were like other languages and started at 0 and not 1, this would be a non-issue =/