for statement problem

Post Reply
luciferleftwing
Member
Posts: 10
Joined: Tue Oct 23, 2012 14:21

for statement problem

by luciferleftwing » Post

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

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

User avatar
PilzAdam
Member
Posts: 4026
Joined: Fri Jul 20, 2012 16:19
GitHub: PilzAdam
IRC: PilzAdam
Location: Germany

by PilzAdam » Post

You have to use ipairs() to get the index and the value. With pairs() you get fieldname and value.

luciferleftwing
Member
Posts: 10
Joined: Tue Oct 23, 2012 14:21

by luciferleftwing » Post

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

Post Reply

Who is online

Users browsing this forum: YaCy [Bot] and 14 guests