Loop Issues in Developer Help
|
|
Code:
CraftUpdate(obj/S) var/list/L = list() for(var/obj/Craftables/C in Craftables) L = C.Components for(var/X in L) var/SA = S.Amount if(X == S.BTag) SA -- if(SA < 0) break else L -= X if(length(L) == 0) src.OutputComponents += C return
|
Problem description:
The idea is that when I move an object from Input to inventory and back again to input, it doesn't seem to recreate the output possibilities. I think the problem is prolly with that SA variable I defined, but I don't know what went wrong.
Here is where I call CraftOutput() if needed.
UpdateAll() var/X = 0 ; var/Y = 0 ; var/Z = 0 src.OutputComponents.Cut(1) src << output(null, "Craft.Inventory") src << output(null, "Craft.CraftInput") src << output(null, "Craft.CraftOutput") for(var/obj/A in src.Inventory) winset(src, "Craft.Inventory", "current-cell = [++X]") src << output(A, "Craft.Inventory") for(var/obj/B in src.InputComponents) winset(src, "Craft.CraftInput", "current-cell = [++Y]") src << output(B, "Craft.CraftInput") src.CraftUpdate(B) for(var/obj/C in src.OutputComponents) winset(src, "Craft.CraftOutput", "current-cell = [++Z]") src << output(C, "Craft.CraftOutput") winset(src, "Craft.Inventory", "cells = [X]") winset(src, "Craft.CraftInput", "cells = [Y]") winset(src, "Craft.CraftOutput", "cells = [Z]") return
|
Notes:
I did check to make sure the actual amount wasn't going down. It wasn't. The actual components list is also safe. What's going on?
|
Are you sure?
Remember that lists are actually stored by reference (like objects), not value (like strings or numbers). So when you remove a value from 'L', you're actually removing it from the Craftable's Components list as well. You need to set 'L' to a copy of C.Components.