Page 1 of 1

An issue with tables and crafting

PostPosted: Thu Nov 14, 2013 05:02
by SegFault22
For my mod, I decided to replace the long section of code for each recipe, with a table and a modified "minetest.register_craft" piece of code. Only, it doesn't work. It loads, but just that - no recipes will work. Here is the code:
[spoiler=code (click to view)]
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
local crafting = {
    { "morestuff2:block_granite", "morestuff2:bricks_granite" },
    { "morestuff2:block_marble", "morestuff2:bricks_marble", },
    { "morestuff2:block_basalt", "morestuff2:bricks_basalt", },
    { "morestuff2:block_gneiss", "morestuff2:bricks_gneiss", },
    { "morestuff2:block_limestone", "morestuff2:bricks_limestone", },
    { "morestuff2:block_schist", "morestuff2:bricks_schist", },
    { "morestuff2:block_quartzite", "morestuff2:bricks_quartzite", },
}

for _, row in ipairs(crafting) do
    local craftin = row[1]
    local craftout = row[2]

    minetest.register_craft( {
    output = 'node craftout 8',
    recipe = {
        { 'craftin', 'craftin', 'craftin' },
        { 'craftin', 'craft morestuff2:saw', 'craftin' },
        { 'craftin', 'craftin', 'craftin' },
      },
      replacements = { {'morestuff2:saw', 'morestuff2:saw'}, },
    })

end
[/spoiler]
I tried adding/removing "node" and "craft" before "'craftin'" in the recipe registry, to no avail. Due to the persistence of this problem, I have come here to ask if anyone could point me in the right direction. If you have a suggestion of how to get this to work, please let me know in a reply.
Thank you.

PostPosted: Thu Nov 14, 2013 08:55
by rubenwardy
You have added the craftin and craftout variables as strings.
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
local crafting = {
    { "morestuff2:block_granite", "morestuff2:bricks_granite" },
    { "morestuff2:block_marble", "morestuff2:bricks_marble", },
    { "morestuff2:block_basalt", "morestuff2:bricks_basalt", },
    { "morestuff2:block_gneiss", "morestuff2:bricks_gneiss", },
    { "morestuff2:block_limestone", "morestuff2:bricks_limestone", },
    { "morestuff2:block_schist", "morestuff2:bricks_schist", },
    { "morestuff2:block_quartzite", "morestuff2:bricks_quartzite", },
}

for _, row in ipairs(crafting) do
    local craftin = row[1]
    local craftout = row[2]

    minetest.register_craft( {
    output = craftout..'8',
    recipe = {
        { craftin, craftin, craftin },
        { craftin, 'morestuff2:saw', craftin },
        { craftin, craftin, craftin },
      },
      replacements = { {'morestuff2:saw', 'morestuff2:saw'}, },
    })

end

PostPosted: Thu Nov 14, 2013 22:18
by SegFault22
rubenwardy wrote:You have added the craftin and craftout variables as strings.
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
local crafting = {
    { "morestuff2:block_granite", "morestuff2:bricks_granite" },
    { "morestuff2:block_marble", "morestuff2:bricks_marble", },
    { "morestuff2:block_basalt", "morestuff2:bricks_basalt", },
    { "morestuff2:block_gneiss", "morestuff2:bricks_gneiss", },
    { "morestuff2:block_limestone", "morestuff2:bricks_limestone", },
    { "morestuff2:block_schist", "morestuff2:bricks_schist", },
    { "morestuff2:block_quartzite", "morestuff2:bricks_quartzite", },
}

for _, row in ipairs(crafting) do
    local craftin = row[1]
    local craftout = row[2]

    minetest.register_craft( {
    output = craftout..'8',
    recipe = {
        { craftin, craftin, craftin },
        { craftin, 'morestuff2:saw', craftin },
        { craftin, craftin, craftin },
      },
      replacements = { {'morestuff2:saw', 'morestuff2:saw'}, },
    })

end

I see. Thank you very much, you've just saved my mod several seconds of loading time.