ID:264900
 
Code:
// S = Slot  A = Amount

mob
proc
Update_Stats()
winset(src,"Main.S1","text=\"[contents[1]]\"")
winset(src,"Main.S1A","text=\"[contents[1]]\"")
winset(src,"Main.S2","text=\"[contents[2]]\"")
winset(src,"Main.S2A","text=\"[contents[2]]\"")
winset(src,"Main.S3","text=\"[contents[3]]\"")
winset(src,"Main.S3A","text=\"[contents[3]]\"")
winset(src,"Main.S4","text=\"[contents[4]]\"")
winset(src,"Main.S4A","text=\"[contents[4]]\"")
winset(src,"Main.S5","text=\"[contents[5]]\"")
winset(src,"Main.S5A","text=\"[contents[5]]\"")
winset(src,"Main.S6","text=\"[contents[6]]\"")
winset(src,"Main.S6A","text=\"[contents[6]]\"")
winset(src,"Main.S7","text=\"[contents[7]]\"")
winset(src,"Main.S7A","text=\"[contents[7]]\"")
winset(src,"Main.S8","text=\"[contents[8]]\"")
winset(src,"Main.S8A","text=\"[contents[8]]\"")


Problem description:

runtime error: list index out of bounds
proc name: Update Stats (/mob/proc/Update_Stats)
usr: Guest-3335345902 (/mob)
src: Guest-3335345902 (/mob)
call stack:
Guest-3335345902 (/mob): Update Stats()
Guest-3335345902 (/mob): Loot()

When I execute the function shown using the line usr.Update_Stats()I get this error and I don't know what's going wrong. Also I know I'm showing the item in the amount slot but that's temporary until I sort this first problem out.

Anyone know what's up? Thanks Heaps.


You're attempting to access the nth item of a list that does not have n items in it. What happens if the contents list is empty, for example? What do you think, say, contents[5] is then?
In response to Jp
Problem Solved :

mob
proc
Update_Stats()
var/obj/Lootable/X = /obj/Lootable
var/Repeats = 0
for(X in contents)
Repeats ++
winset(src,"Main.S[Repeats]","text=\"[X.name]\"")
winset(src,"Main.S[Repeats]A","text=\"[X.Amount]\"")


I'd hate not to seem modest but this I think this is a really nice stat updater.
In response to Kyle_ZX
How many of S[num] do you have in the UI? It would seem fair to limit the loop to that number, then world.log if it looks like you'll go over the limit.
In response to Stephen001
Interesting, I didn't know I could do that. The maximum is contents[8] due to my inventory cap.