Page 1 of 1

for statement problem

PostPosted: Mon Nov 12, 2012 06:37
by luciferleftwing
ok so i was tring to add pillows in the form o stairsplus slabs made of wool i tried using a for cycle to irerate a list colors but all the colors i put in make the same slab and even in creative inventory it does not give me the other one
this is my code

Your phone or window isn't wide enough to display the code box. If it's a phone, try rotating it to landscape mode.
Code: Select all
for index,color in pairs({'red','white'}) do
    local material="wool:"..color
    print(index)
    print(color)
    stairsplus.register_slab("wool", material,
            {snappy=1,choppy=2,oddly_breakable_by_hand=2,flammable=3},
            {"wool_"..color..".png"},
            "wool " ..color.." pillow",
            material)
    print(color)
    print(material)
end

PostPosted: Mon Nov 12, 2012 15:27
by PilzAdam
You have to use ipairs() to get the index and the value. With pairs() you get fieldname and value.

PostPosted: Mon Nov 12, 2012 19:20
by luciferleftwing
thanks Adam but the real problem was that i forgot to link the subname parameter of the function to the loop so i was overwriting the same definition at each iteration