ID:674005
 
(See the best response by DarkCampainger.)
Code:
        CraftUpdate(obj/S) // Outputs possible items that you can make from your input - S is the BTag of whatever you put in
var/list/L = list() // Define L to be an empty list
for(var/obj/Craftables/C in Craftables) // Loop through craftables
L = C.Components // Set L to C's components
for(var/X in L) // Loop through L
var/SA = S.Amount
if(X == S.BTag) // If an element in X has S's BTag
SA -- // Reduce SA by 1
if(SA < 0) // If SA is less than 0
break
else // If it's not less than 0
L -= X // Remove X from L
if(length(L) == 0) // If L is empty
src.OutputComponents += C // Add C to the player's output components
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() // Update All - Updates the grids to output correct information
var/X = 0 ; var/Y = 0 ; var/Z = 0
src.OutputComponents.Cut(1) // This will clear the output list
src << output(null, "Craft.Inventory") // These 3 lines clear the grids (So you don't get duplicates)
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?
Best response
Lugia319 wrote:
The actual components list is also safe.

L = C.Components // Set L to C's components
// ...
L -= X // Remove X from L


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.
The reason I assumed that the components were safe was because I had another 2 lines in when I was testing it

else
C.Components = initial(C.Components)


But I'll try setting it to a copy and seeing what happens.

EDIT: Making a fool out of me as always. You were right. I'll try to remember the list thing from now on.